client-toolkit icon indicating copy to clipboard operation
client-toolkit copied to clipboard

[Question] Using `Queue` / `EventLoop` with requests properly

Open JakeStanger opened this issue 1 year ago • 2 comments

Hey, I'm using the client toolkit for my project and have managed to hook up the wlr-foreign-toplevel-management-unstable-v1 protocol.

I'm receiving events from the manager successfully using the calloop::EventLoop:

let mut event_loop = calloop::EventLoop::<()>::try_new().unwrap();
WaylandSource::new(queue)
    .quick_insert(event_loop.handle())
    .unwrap();

loop {
    event_loop.dispatch(None, &mut ()).unwrap();
}

Elsewhere I'm trying to send a request using wlr_foreign_toplevel_handle_v1::activate where I'm encountering an issue - the nature of the event loop means it waits for events before sending requests, so the activate request doesn't actually go through until the manager receives a different event. I can get round this by sticking a short timeout (50ms) on the loop.

My question is this: is the timeout the correct approach to go about this, or is there some mechanism I'm missing with Wayland or calloop which I can call after activate() that'll force-process requests?

JakeStanger avatar Oct 10 '22 18:10 JakeStanger

If you send the request inside the Dispatch handlers, it should be flushed automatically. If you do it from a timer or via dbus you will need to flush the connection.

Also make sure you are using wayland-client beta 10, there was a bug in beta 9

If you want to know that the request has been processed, you can do a roundtrip if you want to block or send WlDisplay::sync manually and listen for the callback being invoked.

i509VCB avatar Oct 10 '22 19:10 i509VCB

Thanks for the reply. It sounds like my use case calls for a full flush, in which case I think I need to be calling sync_roundtrip on the queue?

JakeStanger avatar Oct 10 '22 19:10 JakeStanger

sync_roundtrip could work, just note that the queue will block until that message is received.

i509VCB avatar Oct 17 '22 14:10 i509VCB

If you have any further questions, feel free to open a new issue or comment here.

i509VCB avatar Nov 07 '22 04:11 i509VCB