Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GObject.registerClass #22

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

vixalien
Copy link
Contributor

@vixalien vixalien commented Dec 26, 2023

Warning

The current code is incomplete and won't run; it is awaiting merge from other dependency pull requests. I'll push all the code after the required branches have been merged (so I can test against the main branch)

This PR will include code that will allow the use of GObject.registerClass in a fashion similar to what GJS already does.

GObject.registerClass allows the following:

  • Registers the class within the GObject type system so that the class can be used, for example, in GtkBuilder using a name and possibly custom GTypeFlags.
  • Allow registering properties with GParamSpecs
  • Allow registering object signals so that we can use obj.connect("signal_name")

It also allows higher integration with GtkWidget:

  • Automatically use a Template URI for constructing Builder objects.
  • Automatically get children and internal children inside said Builder template.
  • Allow setting a widget's css-name using GtkWidget.set_css_name.

Things to do in the future possibly:

  • Set internal children as private properties using # syntax. I am not sure if it's typescript-friendly
  • Consider allowing decorators (supported in Deno) to register properties automatically.

fix #20

@vixalien
Copy link
Contributor Author

fix #20

@vixalien
Copy link
Contributor Author

This is currently in a working stage I'd say. More tests are required though, and some features are not yet implemented. These include:

  • Properties
  • Signals
  • GTypeFlags
  • Builder callbacks, like so: <signal name="clicked" handler="hello_button__clicked" />
  • Allow doing just GObject.registerClass without providing any metadata (infer name automatically)

And possibly more. For reference, these were the main sources of implementation:

@vixalien vixalien marked this pull request as ready for review January 31, 2024 22:00
@vixalien vixalien marked this pull request as draft February 4, 2024 00:59
This runs JS constructors on objects that were not constructed from
JavaScript. These are effectively objects constructed from GtkBuilder.

This is done by tracking all objects currently being constructed in a
variable named `ConstructContext`. If an object's `TypeInfo`'s
`instance_init` method (see
https://docs.gtk.org/gobject/struct.TypeInfo.html) while it's gType is
not the currently being constructed type (i.e. the last element of
`ConstructContext`), it is assumed that the object is being constructed
from GtkBuilder and the object's constructor is called, but instead of
creating a new `GObject`, the constructed object's `gi:ref` (pointer)
is passed instead, and the javascript "construction" continues.
fixes cases like `error instanceof GLib.UriError`
A very good example is `GFile` as returned by `Gio.File.new_for_uri` which is an interface. However, since it's also an object, the unbox function will incorrectly set it to `GObject`.
I'm very sorry for this huge commit. It turns out I was working in an entirely different repo while I was waiting for other necessary PRs to get merged, and hence all the history was lost.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GObject.registerClass
1 participant