1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type FrameClockClass struct {
17 _ structs.HostLayout
18}
19
20func (x *FrameClockClass) GoPointer() uintptr {
21 return uintptr(unsafe.Pointer(x))
22}
23
24type FrameClockPrivate struct {
25 _ structs.HostLayout
26}
27
28func (x *FrameClockPrivate) GoPointer() uintptr {
29 return uintptr(unsafe.Pointer(x))
30}
31
32// Used to represent the different paint clock phases that can be requested.
33//
34// The elements of the enumeration correspond to the signals of `GdkFrameClock`.
35type FrameClockPhase int
36
37var xFrameClockPhaseGLibType func() types.GType
38
39func FrameClockPhaseGLibType() types.GType {
40 return xFrameClockPhaseGLibType()
41}
42
43const (
44
45 // no phase
46 FrameClockPhaseNoneValue FrameClockPhase = 0
47 // corresponds to GdkFrameClock::flush-events. Should not be handled by applications.
48 FrameClockPhaseFlushEventsValue FrameClockPhase = 1
49 // corresponds to GdkFrameClock::before-paint. Should not be handled by applications.
50 FrameClockPhaseBeforePaintValue FrameClockPhase = 2
51 // corresponds to GdkFrameClock::update.
52 FrameClockPhaseUpdateValue FrameClockPhase = 4
53 // corresponds to GdkFrameClock::layout. Should not be handled by applications.
54 FrameClockPhaseLayoutValue FrameClockPhase = 8
55 // corresponds to GdkFrameClock::paint.
56 FrameClockPhasePaintValue FrameClockPhase = 16
57 // corresponds to GdkFrameClock::resume-events. Should not be handled by applications.
58 FrameClockPhaseResumeEventsValue FrameClockPhase = 32
59 // corresponds to GdkFrameClock::after-paint. Should not be handled by applications.
60 FrameClockPhaseAfterPaintValue FrameClockPhase = 64
61)
62
63// Tells the application when to update and repaint a surface.
64//
65// This may be synced to the vertical refresh rate of the monitor, for example.
66// Even when the frame clock uses a simple timer rather than a hardware-based
67// vertical sync, the frame clock helps because it ensures everything paints at
68// the same time (reducing the total number of frames).
69//
70// The frame clock can also automatically stop painting when it knows the frames
71// will not be visible, or scale back animation framerates.
72//
73// `GdkFrameClock` is designed to be compatible with an OpenGL-based implementation
74// or with mozRequestAnimationFrame in Firefox, for example.
75//
76// A frame clock is idle until someone requests a frame with
77// [method@Gdk.FrameClock.request_phase]. At some later point that makes sense
78// for the synchronization being implemented, the clock will process a frame and
79// emit signals for each phase that has been requested. (See the signals of the
80// `GdkFrameClock` class for documentation of the phases.
81// %GDK_FRAME_CLOCK_PHASE_UPDATE and the [signal@Gdk.FrameClock::update] signal
82// are most interesting for application writers, and are used to update the
83// animations, using the frame time given by [method@Gdk.FrameClock.get_frame_time].
84//
85// The frame time is reported in microseconds and generally in the same
86// timescale as g_get_monotonic_time(), however, it is not the same
87// as g_get_monotonic_time(). The frame time does not advance during
88// the time a frame is being painted, and outside of a frame, an attempt
89// is made so that all calls to [method@Gdk.FrameClock.get_frame_time] that
90// are called at a “similar” time get the same value. This means that
91// if different animations are timed by looking at the difference in
92// time between an initial value from [method@Gdk.FrameClock.get_frame_time]
93// and the value inside the [signal@Gdk.FrameClock::update] signal of the clock,
94// they will stay exactly synchronized.
95type FrameClock struct {
96 gobject.Object
97}
98
99var xFrameClockGLibType func() types.GType
100
101func FrameClockGLibType() types.GType {
102 return xFrameClockGLibType()
103}
104
105func FrameClockNewFromInternalPtr(ptr uintptr) *FrameClock {
106 cls := &FrameClock{}
107 cls.Ptr = ptr
108 return cls
109}
110
111var xFrameClockBeginUpdating func(uintptr)
112
113// Starts updates for an animation.
114//
115// Until a matching call to [method@Gdk.FrameClock.end_updating] is made,
116// the frame clock will continually request a new frame with the
117// %GDK_FRAME_CLOCK_PHASE_UPDATE phase. This function may be called multiple
118// times and frames will be requested until gdk_frame_clock_end_updating()
119// is called the same number of times.
120func (x *FrameClock) BeginUpdating() {
121
122 xFrameClockBeginUpdating(x.GoPointer())
123
124}
125
126var xFrameClockEndUpdating func(uintptr)
127
128// Stops updates for an animation.
129//
130// See the documentation for [method@Gdk.FrameClock.begin_updating].
131func (x *FrameClock) EndUpdating() {
132
133 xFrameClockEndUpdating(x.GoPointer())
134
135}
136
137var xFrameClockGetCurrentTimings func(uintptr) *FrameTimings
138
139// Gets the frame timings for the current frame.
140func (x *FrameClock) GetCurrentTimings() *FrameTimings {
141
142 cret := xFrameClockGetCurrentTimings(x.GoPointer())
143 return cret
144}
145
146var xFrameClockGetFps func(uintptr) float64
147
148// Calculates the current frames-per-second, based on the
149// frame timings of @frame_clock.
150func (x *FrameClock) GetFps() float64 {
151
152 cret := xFrameClockGetFps(x.GoPointer())
153 return cret
154}
155
156var xFrameClockGetFrameCounter func(uintptr) int64
157
158// `GdkFrameClock` maintains a 64-bit counter that increments for
159// each frame drawn.
160func (x *FrameClock) GetFrameCounter() int64 {
161
162 cret := xFrameClockGetFrameCounter(x.GoPointer())
163 return cret
164}
165
166var xFrameClockGetFrameTime func(uintptr) int64
167
168// Gets the time that should currently be used for animations.
169//
170// Inside the processing of a frame, it’s the time used to compute the
171// animation position of everything in a frame. Outside of a frame, it's
172// the time of the conceptual “previous frame,” which may be either
173// the actual previous frame time, or if that’s too old, an updated
174// time.
175func (x *FrameClock) GetFrameTime() int64 {
176
177 cret := xFrameClockGetFrameTime(x.GoPointer())
178 return cret
179}
180
181var xFrameClockGetHistoryStart func(uintptr) int64
182
183// Returns the frame counter for the oldest frame available in history.
184//
185// `GdkFrameClock` internally keeps a history of `GdkFrameTimings`
186// objects for recent frames that can be retrieved with
187// [method@Gdk.FrameClock.get_timings]. The set of stored frames
188// is the set from the counter values given by
189// [method@Gdk.FrameClock.get_history_start] and
190// [method@Gdk.FrameClock.get_frame_counter], inclusive.
191func (x *FrameClock) GetHistoryStart() int64 {
192
193 cret := xFrameClockGetHistoryStart(x.GoPointer())
194 return cret
195}
196
197var xFrameClockGetRefreshInfo func(uintptr, int64, *int64, *int64)
198
199// Predicts a presentation time, based on history.
200//
201// Using the frame history stored in the frame clock, finds the last
202// known presentation time and refresh interval, and assuming that
203// presentation times are separated by the refresh interval,
204// predicts a presentation time that is a multiple of the refresh
205// interval after the last presentation time, and later than @base_time.
206func (x *FrameClock) GetRefreshInfo(BaseTimeVar int64, RefreshIntervalReturnVar *int64, PresentationTimeReturnVar *int64) {
207
208 xFrameClockGetRefreshInfo(x.GoPointer(), BaseTimeVar, RefreshIntervalReturnVar, PresentationTimeReturnVar)
209
210}
211
212var xFrameClockGetTimings func(uintptr, int64) *FrameTimings
213
214// Retrieves a `GdkFrameTimings` object holding timing information
215// for the current frame or a recent frame.
216//
217// The `GdkFrameTimings` object may not yet be complete: see
218// [method@Gdk.FrameTimings.get_complete] and
219// [method@Gdk.FrameClock.get_history_start].
220func (x *FrameClock) GetTimings(FrameCounterVar int64) *FrameTimings {
221
222 cret := xFrameClockGetTimings(x.GoPointer(), FrameCounterVar)
223 return cret
224}
225
226var xFrameClockRequestPhase func(uintptr, FrameClockPhase)
227
228// Asks the frame clock to run a particular phase.
229//
230// The signal corresponding the requested phase will be emitted the next
231// time the frame clock processes. Multiple calls to
232// gdk_frame_clock_request_phase() will be combined together
233// and only one frame processed. If you are displaying animated
234// content and want to continually request the
235// %GDK_FRAME_CLOCK_PHASE_UPDATE phase for a period of time,
236// you should use [method@Gdk.FrameClock.begin_updating] instead,
237// since this allows GTK to adjust system parameters to get maximally
238// smooth animations.
239func (x *FrameClock) RequestPhase(PhaseVar FrameClockPhase) {
240
241 xFrameClockRequestPhase(x.GoPointer(), PhaseVar)
242
243}
244
245func (c *FrameClock) GoPointer() uintptr {
246 if c == nil {
247 return 0
248 }
249 return c.Ptr
250}
251
252func (c *FrameClock) SetGoPointer(ptr uintptr) {
253 c.Ptr = ptr
254}
255
256// This signal ends processing of the frame.
257//
258// Applications should generally not handle this signal.
259func (x *FrameClock) ConnectAfterPaint(cb *func(FrameClock)) uint {
260 cbPtr := uintptr(unsafe.Pointer(cb))
261 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
262 handlerID := gobject.SignalConnect(x.GoPointer(), "after-paint", cbRefPtr)
263 glib.SaveHandlerMapping(handlerID, cbPtr)
264 return handlerID
265 }
266
267 fcb := func(clsPtr uintptr) {
268 fa := FrameClock{}
269 fa.Ptr = clsPtr
270 cbFn := *cb
271
272 cbFn(fa)
273
274 }
275 cbRefPtr := purego.NewCallback(fcb)
276 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
277 handlerID := gobject.SignalConnect(x.GoPointer(), "after-paint", cbRefPtr)
278 glib.SaveHandlerMapping(handlerID, cbPtr)
279 return handlerID
280}
281
282// Begins processing of the frame.
283//
284// Applications should generally not handle this signal.
285func (x *FrameClock) ConnectBeforePaint(cb *func(FrameClock)) uint {
286 cbPtr := uintptr(unsafe.Pointer(cb))
287 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
288 handlerID := gobject.SignalConnect(x.GoPointer(), "before-paint", cbRefPtr)
289 glib.SaveHandlerMapping(handlerID, cbPtr)
290 return handlerID
291 }
292
293 fcb := func(clsPtr uintptr) {
294 fa := FrameClock{}
295 fa.Ptr = clsPtr
296 cbFn := *cb
297
298 cbFn(fa)
299
300 }
301 cbRefPtr := purego.NewCallback(fcb)
302 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
303 handlerID := gobject.SignalConnect(x.GoPointer(), "before-paint", cbRefPtr)
304 glib.SaveHandlerMapping(handlerID, cbPtr)
305 return handlerID
306}
307
308// Used to flush pending motion events that are being batched up and
309// compressed together.
310//
311// Applications should not handle this signal.
312func (x *FrameClock) ConnectFlushEvents(cb *func(FrameClock)) uint {
313 cbPtr := uintptr(unsafe.Pointer(cb))
314 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
315 handlerID := gobject.SignalConnect(x.GoPointer(), "flush-events", cbRefPtr)
316 glib.SaveHandlerMapping(handlerID, cbPtr)
317 return handlerID
318 }
319
320 fcb := func(clsPtr uintptr) {
321 fa := FrameClock{}
322 fa.Ptr = clsPtr
323 cbFn := *cb
324
325 cbFn(fa)
326
327 }
328 cbRefPtr := purego.NewCallback(fcb)
329 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
330 handlerID := gobject.SignalConnect(x.GoPointer(), "flush-events", cbRefPtr)
331 glib.SaveHandlerMapping(handlerID, cbPtr)
332 return handlerID
333}
334
335// Emitted as the second step of toolkit and application processing
336// of the frame.
337//
338// Any work to update sizes and positions of application elements
339// should be performed. GTK normally handles this internally.
340func (x *FrameClock) ConnectLayout(cb *func(FrameClock)) uint {
341 cbPtr := uintptr(unsafe.Pointer(cb))
342 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
343 handlerID := gobject.SignalConnect(x.GoPointer(), "layout", cbRefPtr)
344 glib.SaveHandlerMapping(handlerID, cbPtr)
345 return handlerID
346 }
347
348 fcb := func(clsPtr uintptr) {
349 fa := FrameClock{}
350 fa.Ptr = clsPtr
351 cbFn := *cb
352
353 cbFn(fa)
354
355 }
356 cbRefPtr := purego.NewCallback(fcb)
357 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
358 handlerID := gobject.SignalConnect(x.GoPointer(), "layout", cbRefPtr)
359 glib.SaveHandlerMapping(handlerID, cbPtr)
360 return handlerID
361}
362
363// Emitted as the third step of toolkit and application processing
364// of the frame.
365//
366// The frame is repainted. GDK normally handles this internally and
367// emits [signal@Gdk.Surface::render] signals which are turned into
368// [GtkWidget::snapshot](../gtk4/signal.Widget.snapshot.html) signals
369// by GTK.
370func (x *FrameClock) ConnectPaint(cb *func(FrameClock)) uint {
371 cbPtr := uintptr(unsafe.Pointer(cb))
372 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
373 handlerID := gobject.SignalConnect(x.GoPointer(), "paint", cbRefPtr)
374 glib.SaveHandlerMapping(handlerID, cbPtr)
375 return handlerID
376 }
377
378 fcb := func(clsPtr uintptr) {
379 fa := FrameClock{}
380 fa.Ptr = clsPtr
381 cbFn := *cb
382
383 cbFn(fa)
384
385 }
386 cbRefPtr := purego.NewCallback(fcb)
387 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
388 handlerID := gobject.SignalConnect(x.GoPointer(), "paint", cbRefPtr)
389 glib.SaveHandlerMapping(handlerID, cbPtr)
390 return handlerID
391}
392
393// Emitted after processing of the frame is finished.
394//
395// This signal is handled internally by GTK to resume normal
396// event processing. Applications should not handle this signal.
397func (x *FrameClock) ConnectResumeEvents(cb *func(FrameClock)) uint {
398 cbPtr := uintptr(unsafe.Pointer(cb))
399 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
400 handlerID := gobject.SignalConnect(x.GoPointer(), "resume-events", cbRefPtr)
401 glib.SaveHandlerMapping(handlerID, cbPtr)
402 return handlerID
403 }
404
405 fcb := func(clsPtr uintptr) {
406 fa := FrameClock{}
407 fa.Ptr = clsPtr
408 cbFn := *cb
409
410 cbFn(fa)
411
412 }
413 cbRefPtr := purego.NewCallback(fcb)
414 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
415 handlerID := gobject.SignalConnect(x.GoPointer(), "resume-events", cbRefPtr)
416 glib.SaveHandlerMapping(handlerID, cbPtr)
417 return handlerID
418}
419
420// Emitted as the first step of toolkit and application processing
421// of the frame.
422//
423// Animations should be updated using [method@Gdk.FrameClock.get_frame_time].
424// Applications can connect directly to this signal, or use
425// [gtk_widget_add_tick_callback()](../gtk4/method.Widget.add_tick_callback.html)
426// as a more convenient interface.
427func (x *FrameClock) ConnectUpdate(cb *func(FrameClock)) uint {
428 cbPtr := uintptr(unsafe.Pointer(cb))
429 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
430 handlerID := gobject.SignalConnect(x.GoPointer(), "update", cbRefPtr)
431 glib.SaveHandlerMapping(handlerID, cbPtr)
432 return handlerID
433 }
434
435 fcb := func(clsPtr uintptr) {
436 fa := FrameClock{}
437 fa.Ptr = clsPtr
438 cbFn := *cb
439
440 cbFn(fa)
441
442 }
443 cbRefPtr := purego.NewCallback(fcb)
444 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
445 handlerID := gobject.SignalConnect(x.GoPointer(), "update", cbRefPtr)
446 glib.SaveHandlerMapping(handlerID, cbPtr)
447 return handlerID
448}
449
450func init() {
451 core.SetPackageName("GDK", "gtk4")
452 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
453 var libs []uintptr
454 for _, libPath := range core.GetPaths("GDK") {
455 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
456 if err != nil {
457 panic(err)
458 }
459 libs = append(libs, lib)
460 }
461
462 core.PuregoSafeRegister(&xFrameClockPhaseGLibType, libs, "gdk_frame_clock_phase_get_type")
463
464 core.PuregoSafeRegister(&xFrameClockGLibType, libs, "gdk_frame_clock_get_type")
465
466 core.PuregoSafeRegister(&xFrameClockBeginUpdating, libs, "gdk_frame_clock_begin_updating")
467 core.PuregoSafeRegister(&xFrameClockEndUpdating, libs, "gdk_frame_clock_end_updating")
468 core.PuregoSafeRegister(&xFrameClockGetCurrentTimings, libs, "gdk_frame_clock_get_current_timings")
469 core.PuregoSafeRegister(&xFrameClockGetFps, libs, "gdk_frame_clock_get_fps")
470 core.PuregoSafeRegister(&xFrameClockGetFrameCounter, libs, "gdk_frame_clock_get_frame_counter")
471 core.PuregoSafeRegister(&xFrameClockGetFrameTime, libs, "gdk_frame_clock_get_frame_time")
472 core.PuregoSafeRegister(&xFrameClockGetHistoryStart, libs, "gdk_frame_clock_get_history_start")
473 core.PuregoSafeRegister(&xFrameClockGetRefreshInfo, libs, "gdk_frame_clock_get_refresh_info")
474 core.PuregoSafeRegister(&xFrameClockGetTimings, libs, "gdk_frame_clock_get_timings")
475 core.PuregoSafeRegister(&xFrameClockRequestPhase, libs, "gdk_frame_clock_request_phase")
476
477}