1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: ext_data_control_v1
3// Source: ext-data-control-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2018 Simon Ser
7// Copyright © 2019 Ivan Molodetskikh
8// Copyright © 2024 Neal Gompa
9//
10// Permission to use, copy, modify, distribute, and sell this
11// software and its documentation for any purpose is hereby granted
12// without fee, provided that the above copyright notice appear in
13// all copies and that both that copyright notice and this permission
14// notice appear in supporting documentation, and that the name of
15// the copyright holders not be used in advertising or publicity
16// pertaining to distribution of the software without specific,
17// written prior permission. The copyright holders make no
18// representations about the suitability of this software for any
19// purpose. It is provided "as is" without express or implied
20// warranty.
21//
22// THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
23// SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
24// FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
25// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
29// THIS SOFTWARE.
30
31package extdatacontrol
32
33import (
34 "sync"
35
36 cross_wl_seat "github.com/bnema/go-wayland-bindings/client/wayland"
37 "github.com/bnema/wlturbo/wl"
38)
39
40// ERROR_USED_SOURCE is the error used_source value.
41const ERROR_USED_SOURCE = 1
42
43// ERROR_INVALID_OFFER is the error invalid_offer value.
44const ERROR_INVALID_OFFER = 1
45
46// ExtDataControlManagerInterface is the protocol interface name.
47const ExtDataControlManagerInterface = "ext_data_control_manager_v1"
48
49// ExtDataControlManager is the generated binding for ext_data_control_manager_v1 version 1.
50type ExtDataControlManager struct {
51 wl.BaseProxy
52}
53
54// NewExtDataControlManager returns an unbound ExtDataControlManager.
55func NewExtDataControlManager(ctx *wl.Context) *ExtDataControlManager {
56 obj := &ExtDataControlManager{}
57 obj.SetContext(ctx)
58 ctx.Register(obj)
59 return obj
60}
61
62// Create a new data source.
63func (o *ExtDataControlManager) CreateDataSource() (*ExtDataControlSource, error) {
64 child := &ExtDataControlSource{}
65 child.SetContext(o.Context())
66 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_manager_v1.create_data_source", Child: child}, wl.ArgObject(child)); err != nil {
67 return nil, err
68 }
69 return child, nil
70}
71
72// Create a data device that can be used to manage a seat's selection.
73func (o *ExtDataControlManager) GetDataDevice(seat *cross_wl_seat.Seat) (*ExtDataControlDevice, error) {
74 var arg1 wl.Object
75 if seat != nil {
76 arg1 = seat
77 }
78 child := &ExtDataControlDevice{}
79 child.SetContext(o.Context())
80 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_manager_v1.get_data_device", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
81 return nil, err
82 }
83 return child, nil
84}
85
86// All objects created by the manager will still remain valid, until their appropriate destroy request has been called.
87func (o *ExtDataControlManager) Destroy() error {
88 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_data_control_manager_v1.destroy", Destructor: true}); err != nil {
89 return err
90 }
91 return nil
92}
93
94// EventSignature returns the declared event argument types in wire order.
95func (o *ExtDataControlManager) EventSignature(opcode uint16) (string, bool) {
96 switch opcode {
97 default:
98 return "", false
99 }
100}
101
102// Dispatch decodes one event on ext_data_control_manager_v1 and calls the registered handlers.
103func (o *ExtDataControlManager) Dispatch(event *wl.Event) {
104 switch event.Opcode {
105 default:
106 }
107}
108
109// ExtDataControlDeviceInterface is the protocol interface name.
110const ExtDataControlDeviceInterface = "ext_data_control_device_v1"
111
112// ExtDataControlDevice is the generated binding for ext_data_control_device_v1 version 1.
113type ExtDataControlDevice struct {
114 wl.BaseProxy
115 // handlersMu guards the handler slices: a client may register or replace
116 // handlers while another goroutine dispatches events.
117 handlersMu sync.Mutex
118 onDataOffer []func(idObject *ExtDataControlOffer)
119 onSelection []func(idID uint32)
120 onFinished []func()
121 onPrimarySelection []func(idID uint32)
122}
123
124// NewExtDataControlDevice returns an unbound ExtDataControlDevice.
125func NewExtDataControlDevice(ctx *wl.Context) *ExtDataControlDevice {
126 obj := &ExtDataControlDevice{}
127 obj.SetContext(ctx)
128 ctx.Register(obj)
129 return obj
130}
131
132// This request asks the compositor to set the selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source triggers the used_source protocol error. To unset the selection, set the source to NULL.
133func (o *ExtDataControlDevice) SetSelection(source *ExtDataControlSource) error {
134 var arg0 wl.Object
135 if source != nil {
136 arg0 = source
137 }
138 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_device_v1.set_selection"}, wl.ArgObject(arg0)); err != nil {
139 return err
140 }
141 return nil
142}
143
144// Destroys the data device object.
145func (o *ExtDataControlDevice) Destroy() error {
146 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_device_v1.destroy", Destructor: true}); err != nil {
147 return err
148 }
149 return nil
150}
151
152// This request asks the compositor to set the primary selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source triggers the used_source protocol error. To unset the primary selection, set the source to NULL. The compositor will ignore this request if it does not support primary selection.
153func (o *ExtDataControlDevice) SetPrimarySelection(source *ExtDataControlSource) error {
154 var arg0 wl.Object
155 if source != nil {
156 arg0 = source
157 }
158 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_data_control_device_v1.set_primary_selection"}, wl.ArgObject(arg0)); err != nil {
159 return err
160 }
161 return nil
162}
163
164// OnDataOffer registers a handler for the data_offer event.
165//
166// Handlers are appended, so a second call adds another handler rather than
167// replacing the first. Registration is safe while another goroutine dispatches.
168func (o *ExtDataControlDevice) OnDataOffer(handler func(idObject *ExtDataControlOffer)) {
169 if handler == nil {
170 return
171 }
172 o.handlersMu.Lock()
173 defer o.handlersMu.Unlock()
174 o.onDataOffer = append(o.onDataOffer, handler)
175}
176
177// handlersForDataOffer returns the handlers registered for data_offer, taken
178// under the lock so a handler may register another handler while events are
179// being dispatched.
180func (o *ExtDataControlDevice) handlersForDataOffer() []func(idObject *ExtDataControlOffer) {
181 o.handlersMu.Lock()
182 defer o.handlersMu.Unlock()
183 return o.onDataOffer
184}
185
186// OnSelection registers a handler for the selection event.
187//
188// Handlers are appended, so a second call adds another handler rather than
189// replacing the first. Registration is safe while another goroutine dispatches.
190func (o *ExtDataControlDevice) OnSelection(handler func(idID uint32)) {
191 if handler == nil {
192 return
193 }
194 o.handlersMu.Lock()
195 defer o.handlersMu.Unlock()
196 o.onSelection = append(o.onSelection, handler)
197}
198
199// handlersForSelection returns the handlers registered for selection, taken
200// under the lock so a handler may register another handler while events are
201// being dispatched.
202func (o *ExtDataControlDevice) handlersForSelection() []func(idID uint32) {
203 o.handlersMu.Lock()
204 defer o.handlersMu.Unlock()
205 return o.onSelection
206}
207
208// OnFinished registers a handler for the finished event.
209//
210// Handlers are appended, so a second call adds another handler rather than
211// replacing the first. Registration is safe while another goroutine dispatches.
212func (o *ExtDataControlDevice) OnFinished(handler func()) {
213 if handler == nil {
214 return
215 }
216 o.handlersMu.Lock()
217 defer o.handlersMu.Unlock()
218 o.onFinished = append(o.onFinished, handler)
219}
220
221// handlersForFinished returns the handlers registered for finished, taken
222// under the lock so a handler may register another handler while events are
223// being dispatched.
224func (o *ExtDataControlDevice) handlersForFinished() []func() {
225 o.handlersMu.Lock()
226 defer o.handlersMu.Unlock()
227 return o.onFinished
228}
229
230// OnPrimarySelection registers a handler for the primary_selection event.
231//
232// Handlers are appended, so a second call adds another handler rather than
233// replacing the first. Registration is safe while another goroutine dispatches.
234func (o *ExtDataControlDevice) OnPrimarySelection(handler func(idID uint32)) {
235 if handler == nil {
236 return
237 }
238 o.handlersMu.Lock()
239 defer o.handlersMu.Unlock()
240 o.onPrimarySelection = append(o.onPrimarySelection, handler)
241}
242
243// handlersForPrimarySelection returns the handlers registered for primary_selection, taken
244// under the lock so a handler may register another handler while events are
245// being dispatched.
246func (o *ExtDataControlDevice) handlersForPrimarySelection() []func(idID uint32) {
247 o.handlersMu.Lock()
248 defer o.handlersMu.Unlock()
249 return o.onPrimarySelection
250}
251
252// EventSignature returns the declared event argument types in wire order.
253func (o *ExtDataControlDevice) EventSignature(opcode uint16) (string, bool) {
254 switch opcode {
255 case 0:
256 return "new_id,", true
257 case 1:
258 return "object,", true
259 case 2:
260 return "", true
261 case 3:
262 return "object,", true
263 default:
264 return "", false
265 }
266}
267
268// Dispatch decodes one event on ext_data_control_device_v1 and calls the registered handlers.
269func (o *ExtDataControlDevice) Dispatch(event *wl.Event) {
270 switch event.Opcode {
271 case 0: // data_offer
272 idID := event.Uint32()
273 idObject := &ExtDataControlOffer{}
274 idObject.SetContext(o.Context())
275 idObject.SetID(idID)
276 idObject.SetVersion(o.Version())
277 o.Context().Register(idObject)
278
279 for i, handler := range o.handlersForDataOffer() {
280 _ = i
281 handler(idObject)
282 }
283 case 1: // selection
284 idID := event.Uint32()
285
286 for i, handler := range o.handlersForSelection() {
287 _ = i
288 handler(idID)
289 }
290 case 2: // finished
291
292 for i, handler := range o.handlersForFinished() {
293 _ = i
294 handler()
295 }
296 case 3: // primary_selection
297 idID := event.Uint32()
298
299 for i, handler := range o.handlersForPrimarySelection() {
300 _ = i
301 handler(idID)
302 }
303 default:
304 }
305}
306
307// ExtDataControlSourceInterface is the protocol interface name.
308const ExtDataControlSourceInterface = "ext_data_control_source_v1"
309
310// ExtDataControlSource is the generated binding for ext_data_control_source_v1 version 1.
311type ExtDataControlSource struct {
312 wl.BaseProxy
313 // handlersMu guards the handler slices: a client may register or replace
314 // handlers while another goroutine dispatches events.
315 handlersMu sync.Mutex
316 onSend []func(mimeType string, fd *wl.OwnedFD)
317 onCancelled []func()
318}
319
320// NewExtDataControlSource returns an unbound ExtDataControlSource.
321func NewExtDataControlSource(ctx *wl.Context) *ExtDataControlSource {
322 obj := &ExtDataControlSource{}
323 obj.SetContext(ctx)
324 ctx.Register(obj)
325 return obj
326}
327
328// This request adds a MIME type to the set of MIME types advertised to targets. Can be called several times to offer multiple types. Calling this after ext_data_control_device.set_selection is a protocol error.
329func (o *ExtDataControlSource) Offer(mimeType string) error {
330 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_source_v1.offer"}, wl.ArgString(mimeType)); err != nil {
331 return err
332 }
333 return nil
334}
335
336// Destroys the data source object.
337func (o *ExtDataControlSource) Destroy() error {
338 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_source_v1.destroy", Destructor: true}); err != nil {
339 return err
340 }
341 return nil
342}
343
344// OnSend registers a handler for the send event.
345//
346// Handlers are appended, so a second call adds another handler rather than
347// replacing the first. Registration is safe while another goroutine dispatches.
348func (o *ExtDataControlSource) OnSend(handler func(mimeType string, fd *wl.OwnedFD)) {
349 if handler == nil {
350 return
351 }
352 o.handlersMu.Lock()
353 defer o.handlersMu.Unlock()
354 o.onSend = append(o.onSend, handler)
355}
356
357// handlersForSend returns the handlers registered for send, taken
358// under the lock so a handler may register another handler while events are
359// being dispatched.
360func (o *ExtDataControlSource) handlersForSend() []func(mimeType string, fd *wl.OwnedFD) {
361 o.handlersMu.Lock()
362 defer o.handlersMu.Unlock()
363 return o.onSend
364}
365
366// OnCancelled registers a handler for the cancelled event.
367//
368// Handlers are appended, so a second call adds another handler rather than
369// replacing the first. Registration is safe while another goroutine dispatches.
370func (o *ExtDataControlSource) OnCancelled(handler func()) {
371 if handler == nil {
372 return
373 }
374 o.handlersMu.Lock()
375 defer o.handlersMu.Unlock()
376 o.onCancelled = append(o.onCancelled, handler)
377}
378
379// handlersForCancelled returns the handlers registered for cancelled, taken
380// under the lock so a handler may register another handler while events are
381// being dispatched.
382func (o *ExtDataControlSource) handlersForCancelled() []func() {
383 o.handlersMu.Lock()
384 defer o.handlersMu.Unlock()
385 return o.onCancelled
386}
387
388// EventSignature returns the declared event argument types in wire order.
389func (o *ExtDataControlSource) EventSignature(opcode uint16) (string, bool) {
390 switch opcode {
391 case 0:
392 return "string,fd,", true
393 case 1:
394 return "", true
395 default:
396 return "", false
397 }
398}
399
400// Dispatch decodes one event on ext_data_control_source_v1 and calls the registered handlers.
401func (o *ExtDataControlSource) Dispatch(event *wl.Event) {
402 switch event.Opcode {
403 case 0: // send
404 mimeType := event.String()
405 fd := event.FD()
406 ownedfd := fd
407 defer ownedfd.Close()
408
409 for i, handler := range o.handlersForSend() {
410 if i > 0 {
411 fd = nil
412 }
413 handler(mimeType, fd)
414 }
415 case 1: // cancelled
416
417 for i, handler := range o.handlersForCancelled() {
418 _ = i
419 handler()
420 }
421 default:
422 }
423}
424
425// ExtDataControlOfferInterface is the protocol interface name.
426const ExtDataControlOfferInterface = "ext_data_control_offer_v1"
427
428// ExtDataControlOffer is the generated binding for ext_data_control_offer_v1 version 1.
429type ExtDataControlOffer struct {
430 wl.BaseProxy
431 // handlersMu guards the handler slices: a client may register or replace
432 // handlers while another goroutine dispatches events.
433 handlersMu sync.Mutex
434 onOffer []func(mimeType string)
435}
436
437// NewExtDataControlOffer returns an unbound ExtDataControlOffer.
438func NewExtDataControlOffer(ctx *wl.Context) *ExtDataControlOffer {
439 obj := &ExtDataControlOffer{}
440 obj.SetContext(ctx)
441 ctx.Register(obj)
442 return obj
443}
444
445// To transfer the offered data, the client issues this request and indicates the MIME type it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the MIME type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and then closes its end, at which point the transfer is complete. This request may happen multiple times for different MIME types.
446func (o *ExtDataControlOffer) Receive(mimeType string, fd int) error {
447 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_offer_v1.receive", FDs: []int{fd}}, wl.ArgString(mimeType), wl.ArgFD()); err != nil {
448 return err
449 }
450 return nil
451}
452
453// Destroys the data offer object.
454func (o *ExtDataControlOffer) Destroy() error {
455 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_offer_v1.destroy", Destructor: true}); err != nil {
456 return err
457 }
458 return nil
459}
460
461// OnOffer registers a handler for the offer event.
462//
463// Handlers are appended, so a second call adds another handler rather than
464// replacing the first. Registration is safe while another goroutine dispatches.
465func (o *ExtDataControlOffer) OnOffer(handler func(mimeType string)) {
466 if handler == nil {
467 return
468 }
469 o.handlersMu.Lock()
470 defer o.handlersMu.Unlock()
471 o.onOffer = append(o.onOffer, handler)
472}
473
474// handlersForOffer returns the handlers registered for offer, taken
475// under the lock so a handler may register another handler while events are
476// being dispatched.
477func (o *ExtDataControlOffer) handlersForOffer() []func(mimeType string) {
478 o.handlersMu.Lock()
479 defer o.handlersMu.Unlock()
480 return o.onOffer
481}
482
483// EventSignature returns the declared event argument types in wire order.
484func (o *ExtDataControlOffer) EventSignature(opcode uint16) (string, bool) {
485 switch opcode {
486 case 0:
487 return "string,", true
488 default:
489 return "", false
490 }
491}
492
493// Dispatch decodes one event on ext_data_control_offer_v1 and calls the registered handlers.
494func (o *ExtDataControlOffer) Dispatch(event *wl.Event) {
495 switch event.Opcode {
496 case 0: // offer
497 mimeType := event.String()
498
499 for i, handler := range o.handlersForOffer() {
500 _ = i
501 handler(mimeType)
502 }
503 default:
504 }
505}