From 18f92ecd75743574242729c6b9035d786a24bbd3 Mon Sep 17 00:00:00 2001 From: Roman Stingler Date: Mon, 3 Aug 2026 13:40:40 +0200 Subject: [PATCH] only listen for Escape while it can close a menu --- src/app.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index 831660ed..d5123574 100644 --- a/src/app.rs +++ b/src/app.rs @@ -715,18 +715,25 @@ impl App { _ => Message::None, }), iced::output_events().map(Message::OutputEvent), - listen_with(move |evt, _, _| match evt { - iced::event::Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => { - debug!("Keyboard event received: {key:?}"); - if matches!(key, keyboard::Key::Named(keyboard::key::Named::Escape)) { - debug!("ESC key pressed, closing all menus"); - Some(Message::CloseAllMenus) - } else { - None + // Only listen while Escape can close a menu; an idle listener + // subscription still receives every interaction event and would + // overflow iced's fixed-size event channel for nothing. + if self.general_config.enable_esc_key && self.outputs.menu_is_open() { + listen_with(|evt, _, _| match evt { + iced::event::Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => { + debug!("Keyboard event received: {key:?}"); + if matches!(key, keyboard::Key::Named(keyboard::key::Named::Escape)) { + debug!("ESC key pressed, closing all menus"); + Some(Message::CloseAllMenus) + } else { + None + } } - } - _ => None, - }), + _ => None, + }) + } else { + Subscription::none() + }, Subscription::run(|| match signal_hook_tokio::Signals::new([libc::SIGUSR1]) { Ok(signals) => signals .filter_map(|sig| {