Skip to content

Commit

Permalink
Add glib.Object.{Freeze,Thaw}Notify
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Jan 12, 2024
1 parent c873a85 commit fac0f35
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gir/girgen/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ var objectorMethods = map[string]struct{}{
"NotifyProperty": {},
"ObjectProperty": {},
"SetObjectProperty": {},
"FreezeNotify": {},
"ThawNotify": {},
"StopEmission": {},
"Cast": {},
"baseObject": {},
}
Expand Down
34 changes: 33 additions & 1 deletion pkg/core/glib/glib.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ type Objector interface {
NotifyProperty(string, func()) SignalHandle
ObjectProperty(string) interface{}
SetObjectProperty(string, interface{})
FreezeNotify()
ThawNotify()
StopEmission(string)

baseObject() *Object
}
Expand Down Expand Up @@ -780,10 +783,12 @@ func typeFromObject(obj unsafe.Pointer) Type {
return Type(C._g_type_from_instance(C.gpointer(obj)))
}

// StopEmission is a wrapper around g_signal_stop_emission_by_name().
// StopEmission stops a signal’s current emission. It is a wrapper around
// g_signal_stop_emission_by_name().
func (v *Object) StopEmission(s string) {
cstr := C.CString(s)
defer C.free(unsafe.Pointer(cstr))

C.g_signal_stop_emission_by_name((C.gpointer)(v.Native()), (*C.gchar)(cstr))
runtime.KeepAlive(v)
}
Expand Down Expand Up @@ -849,6 +854,33 @@ func (v *Object) NotifyProperty(property string, f func()) SignalHandle {
)
}

// FreezeNotify increases the freeze count on object. If the freeze count is
// non-zero, the emission of “notify” signals on object is stopped. The signals
// are queued until the freeze count is decreased to zero. Duplicate
// notifications are squashed so that at most one GObject::notify signal is
// emitted for each property modified while the object is frozen.
//
// This is necessary for accessors that modify multiple properties to prevent
// premature notification while the object is still being modified.
func (v *Object) FreezeNotify() {
C.g_object_freeze_notify(v.native())
runtime.KeepAlive(v)
}

// ThawNotify reverts the effect of a previous call to g_object_freeze_notify().
// The freeze count is decreased on object and when it reaches zero, queued
// “notify” signals are emitted.
//
// Duplicate notifications for each property are squashed so that at most one
// GObject::notify signal is emitted for each property, in the reverse order in
// which they have been queued.
//
// It is an error to call this function when the freeze count is zero.
func (v *Object) ThawNotify() {
C.g_object_thaw_notify(v.native())
runtime.KeepAlive(v)
}

//export _gotk4_notifyHandlerTramp
func _gotk4_notifyHandlerTramp(obj C.gpointer, paramSpec C.gpointer, closureData C.guintptr) {
closure := ConnectedGeneratedClosure(uintptr(closureData))
Expand Down
1 change: 0 additions & 1 deletion pkg/glib/v2/glib.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fac0f35

Please sign in to comment.