idanarye / woab

Widgets on Actors Bridge - a GUI microframework for combining GTK with Actix
https://crates.io/crates/woab
MIT License
14 stars 1 forks source link

How to add glib sources? #18

Closed piegamesde closed 3 years ago

piegamesde commented 3 years ago

Say I want to connect some closure to timeout_add_local or the like, what's the best way to do this? I guess at the moment I'll have to clone the Addr and then send the event from there, but maybe a Woab-native solution would be preferable. Especially because the Continue return value has very similar problem characteristics to our Inhibit problem.

idanarye commented 3 years ago

Why do you need to involve GTK? Why not do this from Tokio/Actix? Just launch a future that sends the message you want in a loop. Instead of returning Continue, just terminate the loop.

piegamesde commented 3 years ago

That's a very good point, I never thought about this. However, there are a few other methods in that module, and I don't know how accessible alternative implementations are.

In my case, I'll indeed try out what you suggested, but this will probably come up again the day somebody wants to use one of these other methods (if that ever happens ^^).

I'm closing this for now as the implementation cost are probably higher than the workaround cost.

idanarye commented 3 years ago

The main problem here is how to crank the Tokio loop from inside the handler, which I'll already need to solve for #15/#7. I'll just have to expose that ability to the user - something like:

glib::source::timeout_add_local(100, move || {
    let future = addr.send(TickMessage);
    let result = woab::block_on(future);
    glib::source::Continue(result)
});
idanarye commented 3 years ago

I updated Tokio and Actix, and it turns out I had to implement woab::block_on in order to get anything at all to work. Try it out and see if it works for your usecase.