Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
linux: run runnables only when event loop is idle (#12839)
Thorsten Ball43d1a8040d10
diff --git a/crates/gpui/src/platform/linux/wayland/client.rs b/crates/gpui/src/platform/linux/wayland/client.rsindex 2dfd878755f..3e82d32c029 100644--- a/crates/gpui/src/platform/linux/wayland/client.rs+++ b/crates/gpui/src/platform/linux/wayland/client.rs@@ -403,9 +403,14 @@ impl WaylandClient {let handle = event_loop.handle();handle- .insert_source(main_receiver, |event, _, _: &mut WaylandClientStatePtr| {- if let calloop::channel::Event::Msg(runnable) = event {- runnable.run();+ .insert_source(main_receiver, {+ let handle = handle.clone();+ move |event, _, _: &mut WaylandClientStatePtr| {+ if let calloop::channel::Event::Msg(runnable) = event {+ handle.insert_idle(|_| {+ runnable.run();+ });+ }}}).unwrap();diff --git a/crates/gpui/src/platform/linux/x11/client.rs b/crates/gpui/src/platform/linux/x11/client.rsindex 36d11295745..57295ee7726 100644--- a/crates/gpui/src/platform/linux/x11/client.rs+++ b/crates/gpui/src/platform/linux/x11/client.rs@@ -165,9 +165,17 @@ impl X11Client {let handle = event_loop.handle();handle- .insert_source(main_receiver, |event, _, _: &mut X11Client| {- if let calloop::channel::Event::Msg(runnable) = event {- runnable.run();+ .insert_source(main_receiver, {+ let handle = handle.clone();+ move |event, _, _: &mut X11Client| {+ if let calloop::channel::Event::Msg(runnable) = event {+ // Insert the runnables as idle callbacks, so we make sure that user-input and X11+ // events have higher priority and runnables are only worked off after the event+ // callbacks.+ handle.insert_idle(|_| {+ runnable.run();+ });+ }}}).unwrap();