Skip to content

Allow signals handlers to return things - #816

Open
MiaKoring wants to merge 9 commits into
moreSwift:mainfrom
MiaKoring:fix/event-controller-key
Open

MiaKoring wants to merge 9 commits into
moreSwift:mainfrom
MiaKoring:fix/event-controller-key

Conversation

@MiaKoring

@MiaKoring MiaKoring commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Resolves #594

The changes are actually pretty simple:

GtkCodeGen

  • Added SignalReturnInformation with 3 properties:
    • handlerReturnTypeName: The name of the type returned by the generated handler var
    • handlerReturnValueConversionSuffix: in case of gboolean for example it’s nicer to return a Swift Bool in the closure. But for the return to be recognizable by gtk we need to convert it. so in this case, it would be .toGBoolean()
    • defaultReturnValue: The value to return when self or the handler are nil
  • added static allowedSignalReturnTypeInformation with information for gboolean
  • added static signalDefaultReturnOverrides (currently empty, but can be used to override the default return value for a specific signal, afaik Gtk doesn’t have signal naming conflicts, so we should be good here)

generateSignalRegistrationMethod and generateSignalHandlerProperty

For signals with allowed return type information the return value is the specified return value, and the closure returns a default value if self or the handler are nil.

Other signals use Void as return value.

The return value is now specified as an additional generic on SignalBoxN.

On the handler property the new return value is used if applicable or Void if not.

I excluded notify::property signals from the custom logic, as some of them had a boolean return value, which isn’t listed in the GObject notify documentation and I don’t think we need boolean return values on them.

The rest:

SignalBox0 is now used just like any other signal box, as the generic return value cannot be constrained to a C compatible type, so @convention(c) doesn’t work inside it anymore.
All signal boxes got an additional generic R as return value.

All signal registrations in the not-generated part of Gtk and Gtk3 were updated to the new signature (adding Void generic to SignalBoxes or adding a handler property and updating to the new signature for SignalBox0.

The generate.sh Script for some reason removed the buildLimitedAvailability View builder function, idk what’s up with that.

TODOs:

  • make Gtk3Backend compile again
  • cleanup
  • write proper description

@MiaKoring
MiaKoring marked this pull request as ready for review November 17, 2026 15:11

@stackotter stackotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the newly-generated code all looks great. I just have a few requests for the code gen changes themselves.

Comment thread Sources/GtkCodeGen/GtkCodeGen.swift Resolved
Comment thread Sources/GtkCodeGen/GtkCodeGen.swift Resolved
Comment thread Sources/GtkCodeGen/GtkCodeGen.swift Resolved
Comment thread Sources/GtkCodeGen/GtkCodeGen.swift Resolved
@MiaKoring

Copy link
Copy Markdown
Member Author

I'm not entirely sure if it's more readable with the merged branches, but they're merged now 😅

and this was the first real change I did using nvim, yay I guess. It's gonna take a while to get used to it and I need to get some things like automatic closing bracket insertion,...

@MiaKoring
MiaKoring requested a review from stackotter November 22, 2026 01:06

This branch has not been deployed

No deployments
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.

[BUG] Generated EventControllerKey.keyPressed doesn’t support returning Bool

3 participants