[Request] non-void signals
GeopJr opened this issue · 3 comments
Could the signal macro support non-void signals?
Use case:
I'm emitting a singal from a child widget to call another function from the parent and want it to return a bool if it succeeded or not
(exact use case: A widget has a button and a clicked signal. The parent connects to the signal that provides the hash function to copy in string (e.g. "MD5"), the parent then copies it to clipboard and should return a bool to the widget if it succeeded or not so the button displays the correct feedback icon (:heavy_check_mark: or :x:))
You mean: Support signal return values?
Meanwhile it doesn't support, but yes, it's possible to have this.
First step is to let the signal macro register a signal with a return value, so we can inform to GObject the right GType used for the return type at:
https://github.com/hugopl/gi-crystal/blob/main/src/bindings/g_object/object.cr#L596
Then we also need to register a GObject::SignalAcumulator callback.
I never used (or remember to had used) signals with return values, so I would need to do some experiments in libtest to first see it working in C, to later change the macro to let it work in Crystal.
You mean: Support signal return values?
Yes!
I never used (or remember to had used) signals with return values
FWIW, there's quite a few in GTK, here's some: Gtk::ComboBox::PopdownSignal, Gdk::Surface::EventSignal, Gtk::SpinButton::InputSignal