gir icon indicating copy to clipboard operation
gir copied to clipboard

Add a way to connect to signals with `after=true`

Open sdroege opened this issue 5 years ago • 18 comments

See g_signal_connect() vs. g_signal_connect_after() in C. We can already do that via ObjectExt::connect() but it would be useful to also have this for the strongly typed signal connection functions.

Any ideas? @EPashkin @GuillaumeGomez ? :)

sdroege avatar May 14 '20 16:05 sdroege

IMHO currently it not necessary

EPashkin avatar May 14 '20 17:05 EPashkin

What do you mean with not necessary? :) It's needed for correct usage of some APIs.

sdroege avatar May 14 '20 18:05 sdroege

Example please, that we can't cover with bool parameter

EPashkin avatar May 14 '20 18:05 EPashkin

We don't have a bool parameter, that's the problem exactly :)

sdroege avatar May 14 '20 18:05 sdroege

Also, basically all GTK signals that return Inhibit. You might want to connect to them and have your callback called after the default handling is all done already (and e.g. the togglebutton decided if it can toggle or not, if a previous handler returned Inhibit(true) you wouldn't be called anymore, etc).

sdroege avatar May 14 '20 18:05 sdroege

Seems I don't understand question, as we have flag in ObjectExt::connect https://github.com/gtk-rs/glib/blob/ff2e05f017761c751b13cb92a31a027e6397370d/src/object.rs#L1301

EPashkin avatar May 14 '20 18:05 EPashkin

Yes that's the dynamic one with glib::Values everywhere. That's not very nice to use. ButtonExt::connect_clicked for example has no way to connect after.

sdroege avatar May 14 '20 18:05 sdroege

You want to add ButtonExt::connect_clicked_after ? Always or only on config flag?

EPashkin avatar May 14 '20 19:05 EPashkin

That's exactly the question, how to handle that best :)

sdroege avatar May 14 '20 20:05 sdroege

So options I can think of (either always or configurable / opt-in):

  • Add a bool parameter to them (breaks existing code)
  • Add a connect_after_XXX variant (adds lots of new functions that are basically the same)

sdroege avatar May 15 '20 06:05 sdroege

In public interface I prefer connect_after_xxx

EPashkin avatar May 15 '20 08:05 EPashkin

That would mean to duplicate the trampoline though (it's inline inside the connect function).

If we go that way we should probably also make it connect() and connect_after() on ObjectExt for consistency.

sdroege avatar May 15 '20 08:05 sdroege

IMHO changing ObjectExt is not needed

EPashkin avatar May 15 '20 08:05 EPashkin

IMHO changing ObjectExt is not needed

Well, it would be more consistent :)

@guillaumegomez do you have any opinions?

sdroege avatar May 16 '20 08:05 sdroege

Not really. :-/

GuillaumeGomez avatar May 16 '20 10:05 GuillaumeGomez

Then I'd go with connect_XXX and connect_after_XXX for everything, and also do the same for ObjectExt::connect (i.e. add an connect_after there instead of the boolean parameter).

But before doing so I'd wait for @GuillaumeGomez to finish his work on converting the signal handlers to glib::Closures as that's going to touch the same code.

sdroege avatar May 17 '20 06:05 sdroege

Oh, considering my current motivation, it might take a while. :-/

GuillaumeGomez avatar May 17 '20 11:05 GuillaumeGomez

We could maybe make use of const generics here:

pub fn connect_foo<const A: bool, F: Fn()>(&self, func: F) { ... }

However there does not seem to be any syntax to define a default value for const generics (const A: bool = false or something like that)? Without that would become rather annoying to use for the normal case as it would always have to be provided.

sdroege avatar Nov 10 '20 07:11 sdroege