1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "unsafe"
6
7 "github.com/ebitengine/purego"
8
9 "github.com/bnema/puregotk/pkg/core"
10 "github.com/bnema/puregotk/v4/gio"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16// Represents data shared between applications or inside an application.
17//
18// To get a `GdkClipboard` object, use [method@Gdk.Display.get_clipboard] or
19// [method@Gdk.Display.get_primary_clipboard]. You can find out about the data
20// that is currently available in a clipboard using
21// [method@Gdk.Clipboard.get_formats].
22//
23// To make text or image data available in a clipboard, use
24// [method@Gdk.Clipboard.set_text] or [method@Gdk.Clipboard.set_texture].
25// For other data, you can use [method@Gdk.Clipboard.set_content], which
26// takes a [class@Gdk.ContentProvider] object.
27//
28// To read textual or image data from a clipboard, use
29// [method@Gdk.Clipboard.read_text_async] or
30// [method@Gdk.Clipboard.read_texture_async]. For other data, use
31// [method@Gdk.Clipboard.read_async], which provides a `GInputStream` object.
32type Clipboard struct {
33 gobject.Object
34}
35
36var xClipboardGLibType func() types.GType
37
38func ClipboardGLibType() types.GType {
39 return xClipboardGLibType()
40}
41
42func ClipboardNewFromInternalPtr(ptr uintptr) *Clipboard {
43 cls := &Clipboard{}
44 cls.Ptr = ptr
45 return cls
46}
47
48var xClipboardGetContent func(uintptr) uintptr
49
50// Returns the `GdkContentProvider` currently set on @clipboard.
51//
52// If the @clipboard is empty or its contents are not owned by the
53// current process, %NULL will be returned.
54func (x *Clipboard) GetContent() *ContentProvider {
55 var cls *ContentProvider
56
57 cret := xClipboardGetContent(x.GoPointer())
58
59 if cret == 0 {
60 return nil
61 }
62 gobject.IncreaseRef(cret)
63 cls = &ContentProvider{}
64 cls.Ptr = cret
65 return cls
66}
67
68var xClipboardGetDisplay func(uintptr) uintptr
69
70// Gets the `GdkDisplay` that the clipboard was created for.
71func (x *Clipboard) GetDisplay() *Display {
72 var cls *Display
73
74 cret := xClipboardGetDisplay(x.GoPointer())
75
76 if cret == 0 {
77 return nil
78 }
79 gobject.IncreaseRef(cret)
80 cls = &Display{}
81 cls.Ptr = cret
82 return cls
83}
84
85var xClipboardGetFormats func(uintptr) *ContentFormats
86
87// Gets the formats that the clipboard can provide its current contents in.
88func (x *Clipboard) GetFormats() *ContentFormats {
89
90 cret := xClipboardGetFormats(x.GoPointer())
91 return cret
92}
93
94var xClipboardIsLocal func(uintptr) bool
95
96// Returns if the clipboard is local.
97//
98// A clipboard is considered local if it was last claimed
99// by the running application.
100//
101// Note that [method@Gdk.Clipboard.get_content] may return %NULL
102// even on a local clipboard. In this case the clipboard is empty.
103func (x *Clipboard) IsLocal() bool {
104
105 cret := xClipboardIsLocal(x.GoPointer())
106 return cret
107}
108
109var xClipboardReadAsync func(uintptr, []string, int, uintptr, uintptr, uintptr)
110
111// Asynchronously requests an input stream to read the @clipboard's
112// contents from.
113//
114// The clipboard will choose the most suitable mime type from the given list
115// to fulfill the request, preferring the ones listed first.
116func (x *Clipboard) ReadAsync(MimeTypesVar []string, IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
117
118 var CallbackVarRef uintptr
119 if CallbackVar != nil {
120 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
121 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
122 CallbackVarRef = cbRefPtr
123 } else {
124 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
125 cbFn := *CallbackVar
126 cbFn(arg0, arg1, arg2)
127 }
128 CallbackVarRef = purego.NewCallback(fcb)
129 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
130 }
131 }
132
133 xClipboardReadAsync(x.GoPointer(), MimeTypesVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
134
135}
136
137var xClipboardReadFinish func(uintptr, uintptr, *string, **glib.Error) uintptr
138
139// Finishes an asynchronous clipboard read.
140//
141// See [method@Gdk.Clipboard.read_async].
142func (x *Clipboard) ReadFinish(ResultVar gio.AsyncResult, OutMimeTypeVar *string) (*gio.InputStream, error) {
143 var cls *gio.InputStream
144 var cerr *glib.Error
145
146 cret := xClipboardReadFinish(x.GoPointer(), ResultVar.GoPointer(), OutMimeTypeVar, &cerr)
147
148 if cret == 0 {
149 return nil, cerr
150 }
151 cls = &gio.InputStream{}
152 cls.Ptr = cret
153 if cerr == nil {
154 return cls, nil
155 }
156 return cls, cerr
157
158}
159
160var xClipboardReadTextAsync func(uintptr, uintptr, uintptr, uintptr)
161
162// Asynchronously request the @clipboard contents converted to a string.
163//
164// This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
165// Use that function or [method@Gdk.Clipboard.read_async] directly if you
166// need more control over the operation.
167func (x *Clipboard) ReadTextAsync(CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
168
169 var CallbackVarRef uintptr
170 if CallbackVar != nil {
171 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
172 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
173 CallbackVarRef = cbRefPtr
174 } else {
175 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
176 cbFn := *CallbackVar
177 cbFn(arg0, arg1, arg2)
178 }
179 CallbackVarRef = purego.NewCallback(fcb)
180 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
181 }
182 }
183
184 xClipboardReadTextAsync(x.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
185
186}
187
188var xClipboardReadTextFinish func(uintptr, uintptr, **glib.Error) string
189
190// Finishes an asynchronous clipboard read.
191//
192// See [method@Gdk.Clipboard.read_text_async].
193func (x *Clipboard) ReadTextFinish(ResultVar gio.AsyncResult) (string, error) {
194 var cerr *glib.Error
195
196 cret := xClipboardReadTextFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
197 if cerr == nil {
198 return cret, nil
199 }
200 return cret, cerr
201
202}
203
204var xClipboardReadTextureAsync func(uintptr, uintptr, uintptr, uintptr)
205
206// Asynchronously request the @clipboard contents converted to a `GdkPixbuf`.
207//
208// This is a simple wrapper around [method@Gdk.Clipboard.read_value_async].
209// Use that function or [method@Gdk.Clipboard.read_async] directly if you
210// need more control over the operation.
211func (x *Clipboard) ReadTextureAsync(CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
212
213 var CallbackVarRef uintptr
214 if CallbackVar != nil {
215 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
216 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
217 CallbackVarRef = cbRefPtr
218 } else {
219 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
220 cbFn := *CallbackVar
221 cbFn(arg0, arg1, arg2)
222 }
223 CallbackVarRef = purego.NewCallback(fcb)
224 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
225 }
226 }
227
228 xClipboardReadTextureAsync(x.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
229
230}
231
232var xClipboardReadTextureFinish func(uintptr, uintptr, **glib.Error) uintptr
233
234// Finishes an asynchronous clipboard read.
235//
236// See [method@Gdk.Clipboard.read_texture_async].
237func (x *Clipboard) ReadTextureFinish(ResultVar gio.AsyncResult) (*Texture, error) {
238 var cls *Texture
239 var cerr *glib.Error
240
241 cret := xClipboardReadTextureFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
242
243 if cret == 0 {
244 return nil, cerr
245 }
246 cls = &Texture{}
247 cls.Ptr = cret
248 if cerr == nil {
249 return cls, nil
250 }
251 return cls, cerr
252
253}
254
255var xClipboardReadValueAsync func(uintptr, types.GType, int, uintptr, uintptr, uintptr)
256
257// Asynchronously request the @clipboard contents converted to the given
258// @type.
259//
260// For local clipboard contents that are available in the given `GType`,
261// the value will be copied directly. Otherwise, GDK will try to use
262// [func@content_deserialize_async] to convert the clipboard's data.
263func (x *Clipboard) ReadValueAsync(TypeVar types.GType, IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
264
265 var CallbackVarRef uintptr
266 if CallbackVar != nil {
267 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
268 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
269 CallbackVarRef = cbRefPtr
270 } else {
271 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
272 cbFn := *CallbackVar
273 cbFn(arg0, arg1, arg2)
274 }
275 CallbackVarRef = purego.NewCallback(fcb)
276 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
277 }
278 }
279
280 xClipboardReadValueAsync(x.GoPointer(), TypeVar, IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
281
282}
283
284var xClipboardReadValueFinish func(uintptr, uintptr, **glib.Error) *gobject.Value
285
286// Finishes an asynchronous clipboard read.
287//
288// See [method@Gdk.Clipboard.read_value_async].
289func (x *Clipboard) ReadValueFinish(ResultVar gio.AsyncResult) (*gobject.Value, error) {
290 var cerr *glib.Error
291
292 cret := xClipboardReadValueFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
293 if cerr == nil {
294 return cret, nil
295 }
296 return cret, cerr
297
298}
299
300var xClipboardSet func(uintptr, types.GType, ...interface{})
301
302// Sets the clipboard to contain the value collected from the given varargs.
303//
304// Values should be passed the same way they are passed to other value
305// collecting APIs, such as [method@GObject.Object.set] or
306// [func@GObject.signal_emit].
307//
308// ```c
309// gdk_clipboard_set (clipboard, G_TYPE_STRING, "Hello World");
310//
311// gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, some_texture);
312// ```
313func (x *Clipboard) Set(TypeVar types.GType, varArgs ...interface{}) {
314
315 xClipboardSet(x.GoPointer(), TypeVar, varArgs...)
316
317}
318
319var xClipboardSetContent func(uintptr, uintptr) bool
320
321// Sets a new content provider on @clipboard.
322//
323// The clipboard will claim the `GdkDisplay`'s resources and advertise
324// these new contents to other applications.
325//
326// In the rare case of a failure, this function will return %FALSE. The
327// clipboard will then continue reporting its old contents and ignore
328// @provider.
329//
330// If the contents are read by either an external application or the
331// @clipboard's read functions, @clipboard will select the best format to
332// transfer the contents and then request that format from @provider.
333func (x *Clipboard) SetContent(ProviderVar *ContentProvider) bool {
334
335 cret := xClipboardSetContent(x.GoPointer(), ProviderVar.GoPointer())
336 return cret
337}
338
339var xClipboardSetText func(uintptr, string)
340
341// Puts the given @text into the clipboard.
342func (x *Clipboard) SetText(TextVar string) {
343
344 xClipboardSetText(x.GoPointer(), TextVar)
345
346}
347
348var xClipboardSetTexture func(uintptr, uintptr)
349
350// Puts the given @texture into the clipboard.
351func (x *Clipboard) SetTexture(TextureVar *Texture) {
352
353 xClipboardSetTexture(x.GoPointer(), TextureVar.GoPointer())
354
355}
356
357var xClipboardSetValist func(uintptr, types.GType, []interface{})
358
359// Sets the clipboard to contain the value collected from the given @args.
360func (x *Clipboard) SetValist(TypeVar types.GType, ArgsVar []interface{}) {
361
362 xClipboardSetValist(x.GoPointer(), TypeVar, ArgsVar)
363
364}
365
366var xClipboardSetValue func(uintptr, *gobject.Value)
367
368// Sets the @clipboard to contain the given @value.
369func (x *Clipboard) SetValue(ValueVar *gobject.Value) {
370
371 xClipboardSetValue(x.GoPointer(), ValueVar)
372
373}
374
375var xClipboardStoreAsync func(uintptr, int, uintptr, uintptr, uintptr)
376
377// Asynchronously instructs the @clipboard to store its contents remotely.
378//
379// If the clipboard is not local, this function does nothing but report success.
380//
381// The purpose of this call is to preserve clipboard contents beyond the
382// lifetime of an application, so this function is typically called on
383// exit. Depending on the platform, the functionality may not be available
384// unless a "clipboard manager" is running.
385//
386// This function is called automatically when a
387// [GtkApplication](../gtk4/class.Application.html)
388// is shut down, so you likely don't need to call it.
389func (x *Clipboard) StoreAsync(IoPriorityVar int, CancellableVar *gio.Cancellable, CallbackVar *gio.AsyncReadyCallback, UserDataVar uintptr) {
390
391 var CallbackVarRef uintptr
392 if CallbackVar != nil {
393 CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar))
394 if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok {
395 CallbackVarRef = cbRefPtr
396 } else {
397 fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) {
398 cbFn := *CallbackVar
399 cbFn(arg0, arg1, arg2)
400 }
401 CallbackVarRef = purego.NewCallback(fcb)
402 glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar)
403 }
404 }
405
406 xClipboardStoreAsync(x.GoPointer(), IoPriorityVar, CancellableVar.GoPointer(), CallbackVarRef, UserDataVar)
407
408}
409
410var xClipboardStoreFinish func(uintptr, uintptr, **glib.Error) bool
411
412// Finishes an asynchronous clipboard store.
413//
414// See [method@Gdk.Clipboard.store_async].
415func (x *Clipboard) StoreFinish(ResultVar gio.AsyncResult) (bool, error) {
416 var cerr *glib.Error
417
418 cret := xClipboardStoreFinish(x.GoPointer(), ResultVar.GoPointer(), &cerr)
419 if cerr == nil {
420 return cret, nil
421 }
422 return cret, cerr
423
424}
425
426func (c *Clipboard) GoPointer() uintptr {
427 if c == nil {
428 return 0
429 }
430 return c.Ptr
431}
432
433func (c *Clipboard) SetGoPointer(ptr uintptr) {
434 c.Ptr = ptr
435}
436
437// GetPropertyFormats gets the "formats" property.
438// The possible formats that the clipboard can provide its data in.
439func (x *Clipboard) GetPropertyFormats() uintptr {
440 var v gobject.Value
441 x.GetProperty("formats", &v)
442 return v.GetPointer()
443}
444
445// GetPropertyLocal gets the "local" property.
446// %TRUE if the contents of the clipboard are owned by this process.
447func (x *Clipboard) GetPropertyLocal() bool {
448 var v gobject.Value
449 x.GetProperty("local", &v)
450 return v.GetBoolean()
451}
452
453// Emitted when the clipboard changes ownership.
454func (x *Clipboard) ConnectChanged(cb *func(Clipboard)) uint {
455 cbPtr := uintptr(unsafe.Pointer(cb))
456 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
457 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
458 glib.SaveHandlerMapping(handlerID, cbPtr)
459 return handlerID
460 }
461
462 fcb := func(clsPtr uintptr) {
463 fa := Clipboard{}
464 fa.Ptr = clsPtr
465 cbFn := *cb
466
467 cbFn(fa)
468
469 }
470 cbRefPtr := purego.NewCallback(fcb)
471 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
472 handlerID := gobject.SignalConnect(x.GoPointer(), "changed", cbRefPtr)
473 glib.SaveHandlerMapping(handlerID, cbPtr)
474 return handlerID
475}
476
477func init() {
478 core.SetPackageName("GDK", "gtk4")
479 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
480 var libs []uintptr
481 for _, libPath := range core.GetPaths("GDK") {
482 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
483 if err != nil {
484 panic(err)
485 }
486 libs = append(libs, lib)
487 }
488
489 core.PuregoSafeRegister(&xClipboardGLibType, libs, "gdk_clipboard_get_type")
490
491 core.PuregoSafeRegister(&xClipboardGetContent, libs, "gdk_clipboard_get_content")
492 core.PuregoSafeRegister(&xClipboardGetDisplay, libs, "gdk_clipboard_get_display")
493 core.PuregoSafeRegister(&xClipboardGetFormats, libs, "gdk_clipboard_get_formats")
494 core.PuregoSafeRegister(&xClipboardIsLocal, libs, "gdk_clipboard_is_local")
495 core.PuregoSafeRegister(&xClipboardReadAsync, libs, "gdk_clipboard_read_async")
496 core.PuregoSafeRegister(&xClipboardReadFinish, libs, "gdk_clipboard_read_finish")
497 core.PuregoSafeRegister(&xClipboardReadTextAsync, libs, "gdk_clipboard_read_text_async")
498 core.PuregoSafeRegister(&xClipboardReadTextFinish, libs, "gdk_clipboard_read_text_finish")
499 core.PuregoSafeRegister(&xClipboardReadTextureAsync, libs, "gdk_clipboard_read_texture_async")
500 core.PuregoSafeRegister(&xClipboardReadTextureFinish, libs, "gdk_clipboard_read_texture_finish")
501 core.PuregoSafeRegister(&xClipboardReadValueAsync, libs, "gdk_clipboard_read_value_async")
502 core.PuregoSafeRegister(&xClipboardReadValueFinish, libs, "gdk_clipboard_read_value_finish")
503 core.PuregoSafeRegister(&xClipboardSet, libs, "gdk_clipboard_set")
504 core.PuregoSafeRegister(&xClipboardSetContent, libs, "gdk_clipboard_set_content")
505 core.PuregoSafeRegister(&xClipboardSetText, libs, "gdk_clipboard_set_text")
506 core.PuregoSafeRegister(&xClipboardSetTexture, libs, "gdk_clipboard_set_texture")
507 core.PuregoSafeRegister(&xClipboardSetValist, libs, "gdk_clipboard_set_valist")
508 core.PuregoSafeRegister(&xClipboardSetValue, libs, "gdk_clipboard_set_value")
509 core.PuregoSafeRegister(&xClipboardStoreAsync, libs, "gdk_clipboard_store_async")
510 core.PuregoSafeRegister(&xClipboardStoreFinish, libs, "gdk_clipboard_store_finish")
511
512}