New progress on the #puregotk#GObject introspection things I'm working on in #Go. It's super early, but I added preliminary support for generated getters/setters for properties. No more manual value setup & SetProperty calls required, just a simple SetPropertyX call. We're getting closer and closer to more readable code here with this IMHO, GJS on the right for comparison!
Continued some #GObject subclassing support in Go. Turns out I messed up the C memory alignment in #Go for and ended up embedding the parent class as a reference, when GObject expects it to be the actual struct. Funnily enough some callbacks still worked before this, but now even the ones like Snapshot and Activate work. To demonstrate, here is a Go application subclassing AdwApplication and overwriting the activate callback instead of calling ConnectCallback!
An example application window with GTK inspector open, showing ExampleApplication as it's type.
Now that my PRs for #GObject subclassing support in Go are up on GitHub and ready for review, I can get started porting over Sessions to GSK instead of Cairo. It was easier to do find examples in JS, so that's what I used, but next up is getting this to work with the freshly implemented snapshot function override!
Sessions running with the GTK inspector open. A custom widget shows up in the inspector.
May I present: Typed subclassing of #GObject classes in Golang! Still a WIP, but this is enough now to create proper custom #GTK widgets in #Golang without needing to import any purego/CGo code to subclass. Please ignore the Constructed callback call here, it's just there to test if getting a callback (e.g. a constructor works), too. 🥳
This source code, in VSCode:
objClass.SetCallbackSetProperty(func(o *gobject.Object, u uint, v *gobject.Value, ps *gobject.ParamSpec) {
switch u {
case propertyIdTestButtonSensitive:
w := (*senbaraGtkMainApplicationWindow)(unsafe.Pointer(o.GetData(dataKeyGoInstance)))
w.buttonTest.SetSensitive(v.GetBoolean())
}
})
objClass.SetCallbackGetProperty(func(o *gobject.Object, u uint, v *gobject.Value, ps *gobject.ParamSpec) {
switch u {
case propertyIdTestButtonSensitive:
w := (*senbaraGtkMainApplicationWindow)(unsafe.Pointer(o.GetData(dataKeyGoInstance)))