Smithay / client-toolkit

Smithay's toolkit for writing wayland clients
MIT License
281 stars 78 forks source link

add example showing how to use tokio #53

Open dvc94ch opened 5 years ago

dvc94ch commented 5 years ago

We should provide some sort of example showing how to send messages from a tokio event loop.

elinorbgr commented 5 years ago

Tbqh I'd like to know how to do that too. Though my overall feeling is that tokio's design is mostly ill-suited for GUI stuff. Unless I'm misunderstanding your intent?

Le 19 décembre 2018 00:27:38 GMT+01:00, David Craven notifications@github.com a écrit :

We should provide some sort of example showing how to send messages from a tokio event loop.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/Smithay/client-toolkit/issues/53

dvc94ch commented 5 years ago

mmh why do you think that?

elinorbgr commented 5 years ago

My understanding of Tokio is that it's mostly geared toward request/response protocols. Actually, future-base designs are well suited for request-response workflows (http, asynchronous computations, etc...) but this seems less obvious to me how GUI stuff fits in that (especially wayland), where you have asynchronous messages. Requests and event are not paired in any way to each other.

That said, I am not opposed to make wayland-client tokio-compatible, but this is not a priority for me, and I don't know how/if it is even possible. But if you come up with a viable design, I'd gladly consider it. I expect this would require changes in wayland-client itself, rather that just SCTK.

valpackett commented 4 years ago

Here's an experiment: a future that does wayland dispatch, plus some functions to get wayland events over channels: https://gist.github.com/myfreeweb/f8e9097e897e26b71b630e5f299a06fe

I ended up going with glib instead of tokio for my current project though: https://github.com/myfreeweb/waysmoke/blob/9b82905e4fbcdef1acabd87825e01e9d2c220285/wstk/src/event_loop.rs

Still using a similar concept for events, but with futures::channel, and the dispatch is very simple at least for now.

danieldg commented 3 years ago

For reference, I am using tokio in my project: https://github.com/danieldg/rwaybar/ - in particular https://github.com/danieldg/rwaybar/blob/master/src/wayland.rs#L389 is the wiring between tokio and wayland_client.

DemiMarie commented 3 years ago

My understanding of Tokio is that it's mostly geared toward request/response protocols. Actually, future-base designs are well suited for request-response workflows (http, asynchronous computations, etc...) but this seems less obvious to me how GUI stuff fits in that (especially wayland), where you have asynchronous messages. Requests and event are not paired in any way to each other.

One might want to make HTTP requests from one’s GUI application.