Skip to content

Commit

Permalink
fix(focused): incorrectly clearing when unfocused window title changes (
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger authored and nyadiia committed May 3, 2024
1 parent 617236a commit 60c28cf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/modules/focused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ impl Module<gtk::Box> for FocusedModule {
let wl = context.client::<wayland::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)))
Expand All @@ -77,22 +81,29 @@ impl Module<gtk::Box> 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((
info.title.clone(),
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));
}
}
Expand Down

0 comments on commit 60c28cf

Please sign in to comment.