diff --git a/internal/gobj/gobj.go b/internal/gobj/gobj.go new file mode 100644 index 00000000..fccaaa9a --- /dev/null +++ b/internal/gobj/gobj.go @@ -0,0 +1,260 @@ +// Package gobj registers Go-backed GObject types. It is the only place +// that touches type registration, class vfuncs, and the map from +// instance pointers to Go values. +package gobj + +import ( + "cmp" + "fmt" + "reflect" + "sync" + "unsafe" + + "codeberg.org/puregotk/puregotk/v4/glib" + "codeberg.org/puregotk/puregotk/v4/gobject" + "codeberg.org/puregotk/puregotk/v4/gobject/types" + "codeberg.org/puregotk/puregotk/v4/gtk" + "deedles.dev/trayscale/internal/gutil" +) + +// Base is embedded in every Go-backed widget. gobj sets it before any +// Go code sees the struct. +type Base struct{ ptr uintptr } + +func (b *Base) base() *Base { return b } + +// GoPointer returns the instance pointer, so a *T can be passed where +// puregotk wants a gobject.Ptr. +func (b *Base) GoPointer() uintptr { return b.ptr } + +// SetGoPointer exists to satisfy gobject.Ptr. Changing the instance of +// a Go-backed widget makes no sense, so it panics. +func (b *Base) SetGoPointer(uintptr) { panic("gobj: SetGoPointer on a Go-backed widget") } + +// Widget returns the instance as a borrowed *gtk.Widget. +func (b *Base) Widget() *gtk.Widget { return gtk.WidgetNewFromInternalPtr(b.ptr) } + +// Disposer is optional. Dispose runs once, from the class dispose, +// while template children are still alive. +type Disposer interface{ Dispose() } + +// WidgetSpec describes one widget subclass. Template is a full .ui +// document whose