From 27f920d01217bedba279003291ad48c1aaa56bb0 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Thu, 29 Jun 2023 16:42:03 +0100 Subject: [PATCH] feat(launcher): slightly improve focus logic when clicking item with multiple windows --- src/modules/launcher/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/launcher/mod.rs b/src/modules/launcher/mod.rs index 46018e8..546230d 100644 --- a/src/modules/launcher/mod.rs +++ b/src/modules/launcher/mod.rs @@ -274,10 +274,14 @@ impl Module for LauncherModule { let items = lock!(items); let id = match event { - ItemEvent::FocusItem(app_id) => items - .get(&app_id) - .and_then(|item| item.windows.first().map(|(_, win)| win.id)), - ItemEvent::FocusWindow(id) => Some(id), // FIXME: Broken on wlroots-git + ItemEvent::FocusItem(app_id) => items.get(&app_id).and_then(|item| { + item.windows + .iter() + .find(|(_, win)| !win.open_state.is_focused()) + .or_else(|| item.windows.first()) + .map(|(_, win)| win.id) + }), + ItemEvent::FocusWindow(id) => Some(id), ItemEvent::OpenItem(_) => unreachable!(), }; @@ -285,6 +289,8 @@ impl Module for LauncherModule { if let Some(window) = items.iter().find_map(|(_, item)| item.windows.get(&id)) { + debug!("Focusing window {id}: {}", window.name); + let seat = wl.get_seats().pop().expect("Failed to get Wayland seat"); window.focus(&seat); }