From 26431d5969f80340c555ee8b02a0d826b4cff21d Mon Sep 17 00:00:00 2001 From: Breadway Date: Sat, 23 May 2026 12:17:56 +0800 Subject: [PATCH] breadbox: fix unfocus-close, Enter, and arrow key navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - KeyboardMode::Exclusive → OnDemand: with Exclusive the compositor never sends wl_keyboard::leave, so EventControllerFocus::connect_leave never fires. OnDemand lets Hyprland hand focus back on click-outside. - Move EventControllerKey from search to window, capture phase: bubble phase on SearchEntry let its own handlers consume Enter and arrows first. Capture phase on the window intercepts all keys before any widget sees them, so Enter/Up/Down/Esc always reach our handler. --- src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e93da63..1287c26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -331,7 +331,7 @@ fn run_ui(entries: Vec<(String, String)>) { window.init_layer_shell(); window.set_layer(Layer::Overlay); - window.set_keyboard_mode(KeyboardMode::Exclusive); + window.set_keyboard_mode(KeyboardMode::OnDemand); window.set_anchor(Edge::Top, true); window.set_exclusive_zone(-1); @@ -402,8 +402,10 @@ fn run_ui(entries: Vec<(String, String)>) { list_f.select_row(first_vis.as_ref()); }); - // Keyboard: Esc, Enter, arrows — keep focus in search bar + // Keyboard: Esc, Enter, arrows — capture phase on window so we + // intercept before SearchEntry's own handlers consume them let key_ctrl = EventControllerKey::new(); + key_ctrl.set_propagation_phase(gtk4::PropagationPhase::Capture); let window_k = window.clone(); let list_k = list.clone(); key_ctrl.connect_key_pressed(move |_, key, _, _| { @@ -461,7 +463,7 @@ fn run_ui(entries: Vec<(String, String)>) { _ => glib::Propagation::Proceed, } }); - search.add_controller(key_ctrl); + window.add_controller(key_ctrl); // Click to launch let window_a = window.clone();