From ea2b20816d459aafe79578f155454d50684f5fad Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Wed, 24 Apr 2024 21:29:44 +0100 Subject: [PATCH] fix(focused): incorrectly clearing when unfocused window title changes (#556) Fixes #544 --- src/modules/focused.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/focused.rs b/src/modules/focused.rs index f132b64..c63d263 100644 --- a/src/modules/focused.rs +++ b/src/modules/focused.rs @@ -62,12 +62,16 @@ impl Module for FocusedModule { let wl = context.client::(); spawn(async move { + let mut current = None; + let mut wlrx = wl.subscribe_toplevels(); let handles = wl.toplevel_info_all(); let focused = handles.into_iter().find(|info| info.focused); if let Some(focused) = focused { + current = Some(focused.id); + try_send!( tx, ModuleUpdateEvent::Update(Some((focused.title.clone(), focused.app_id))) @@ -77,8 +81,12 @@ impl Module for FocusedModule { while let Ok(event) = wlrx.recv().await { match event { ToplevelEvent::Update(info) => { + println!("{current:?} | {info:?}"); if info.focused { debug!("Changing focus"); + + current = Some(info.id); + send_async!( tx, ModuleUpdateEvent::Update(Some(( @@ -86,13 +94,16 @@ impl Module for FocusedModule { info.app_id.clone() ))) ); - } else { + } else if info.id == current.unwrap_or_default() { + debug!("Clearing focus"); + current = None; send_async!(tx, ModuleUpdateEvent::Update(None)); } } ToplevelEvent::Remove(info) => { if info.focused { debug!("Clearing focus"); + current = None; send_async!(tx, ModuleUpdateEvent::Update(None)); } }