Druid: External events

Created on 23 Jan 2020  路  11Comments  路  Source: linebender/druid

How would one react to some event not triggered by user input, like a background thread sending a message over a channel.

All 11 comments

This is one of the most frequently requested features. It should probably be on the roadmap (#434), especially as we've had significant discussions. Previously to the June rearchitecture, there was an ext_event mechanism. We definitely want to bring this back, but there are subtleties in terms of figuring out which window or windows to deliver it to, now that we're multi-window.

This probably should be on the roadmap, I agree. I've been meaning to try and get a simple version done, maybe it's time to revisit that idea.

Hi. I'm really needing this feature. Do you have any idea when it might be available? Thanks.

@zesterer I can look into doing a preliminary implementation. What's your use case? It isn't clear to me what API would make the most sense.

I'm writing a frontend for a game server designed for LAN players. The game server runs in a separate thread, and I want server events from this thread to trigger an update of some or all of the UI (as well as changing the underlying Data).

okay. I played around with this a bit and it's going to take more than an evening, need to figure out what we can safely move between threads. I'm having fun though, so I'll block out some time for this tomorrow.

My thinking would be that you somehow acquire a sender or "proxy" to the UI mainloop that can be sent across threads. From there you have something like submit_command for sending commands normally.

This could probably be implemented with glib::MainContext::channel and something equivalent on other platforms

@Malmz yep that's basically what I was imagining. Got a bunch of stuff hacked together yesterday, but the issue ended up being that Command isn't necessarily thread safe, so might need an ExtCommand variant or something? Need to experiment a bit more.

@zesterer try out #486 and see if it is fit for your purposes? There's an example at druid/examples/ext_event.rs. I'm really not sure what the performance is like on this, and it's a very barebones API, but I hope it covers the simple cases?

@cmyr That's perfect for my uses, thanks! Updates only occur a few times per second so I'm sure this is fine. Is this likely to get merged in the new few days?

@cmyr That's perfect for my uses, thanks! Updates only occur a few times per second so I'm sure this is fine. Is this likely to get merged in the new few days?

Yes, I'm approving now :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

madig picture madig  路  5Comments

timothyhollabaugh picture timothyhollabaugh  路  3Comments

raphlinus picture raphlinus  路  4Comments

raphlinus picture raphlinus  路  5Comments

Finnerale picture Finnerale  路  5Comments