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

Add a way to connect to signals with after=true #964

Open
Tracked by #137
sdroege opened this issue May 14, 2020 · 18 comments
Open
Tracked by #137

Add a way to connect to signals with after=true #964

sdroege opened this issue May 14, 2020 · 18 comments

Comments

@sdroege
Copy link
Member

sdroege commented May 14, 2020

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 ? :)

@EPashkin
Copy link
Member

IMHO currently it not necessary

@sdroege
Copy link
Member Author

sdroege commented May 14, 2020

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

@EPashkin
Copy link
Member

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

@sdroege
Copy link
Member Author

sdroege commented May 14, 2020

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

@sdroege
Copy link
Member Author

sdroege commented May 14, 2020

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).

@EPashkin
Copy link
Member

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

@sdroege
Copy link
Member Author

sdroege commented May 14, 2020

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.

@EPashkin
Copy link
Member

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

@sdroege
Copy link
Member Author

sdroege commented May 14, 2020

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

@sdroege
Copy link
Member Author

sdroege commented May 15, 2020

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)

@EPashkin
Copy link
Member

In public interface I prefer connect_after_xxx

@sdroege
Copy link
Member Author

sdroege commented May 15, 2020

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.

@EPashkin
Copy link
Member

IMHO changing ObjectExt is not needed

@sdroege
Copy link
Member Author

sdroege commented May 16, 2020

IMHO changing ObjectExt is not needed

Well, it would be more consistent :)

@GuillaumeGomez do you have any opinions?

@GuillaumeGomez
Copy link
Member

Not really. :-/

@sdroege
Copy link
Member Author

sdroege commented May 17, 2020

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.

@GuillaumeGomez
Copy link
Member

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

@sdroege sdroege transferred this issue from gtk-rs/glib Sep 14, 2020
@sdroege
Copy link
Member Author

sdroege commented Nov 10, 2020

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.

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

No branches or pull requests

3 participants