From 8f768fd4ca53e02b71c7ea3fa64aa85d624275d3 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 28 Oct 2026 12:20:28 -0700 Subject: [PATCH] fix(process_event): follow focus to the window that came to the front When an application on a hidden workspace came to the front, its focus was not followed to its workspace, and when it was, the window that came to the front was not the one that ended up focused. Follow the notification to its window when the application has no main window to ask for, say when that was needed, and focus the container of that window before the reconciliator loads the workspace, instead of the one the workspace last had focused. The stale focus check then agrees with where focus went. --- komorebi/src/process_event.rs | 16 ++++++++++++++++ komorebi/src/workspace_reconciliator.rs | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index a2c501b3..0bd88bfe 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -450,6 +450,22 @@ impl WindowManager { needs_reconciliation = true; } } + } else { + // An application whose window is parked on a hidden workspace can have no main + // window to ask for when it comes to the front, but the notification may still + // say which window it is about, and that is enough to follow it + tracing::debug!( + "{notification} for process {process_id}: no main window to ask for" + ); + + if !stale + && let Some(window_id) = event.window_id() + && let Some((m_idx, w_idx)) = self.known_window_ids.get(&window_id).cloned() + && !self.focused_workspace()?.contains_window(window_id) + { + workspace_reconciliator::send_notification(m_idx, w_idx, event); + needs_reconciliation = true; + } } if matches!( diff --git a/komorebi/src/workspace_reconciliator.rs b/komorebi/src/workspace_reconciliator.rs index c5ffda21..a066e37e 100644 --- a/komorebi/src/workspace_reconciliator.rs +++ b/komorebi/src/workspace_reconciliator.rs @@ -131,6 +131,18 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let previous_idx = monitor.focused_workspace_idx(); monitor.last_focused_workspace = Option::from(previous_idx); monitor.focus_workspace(notification.workspace_idx)?; + } + + // the window that came to the front is the one to focus, and not whichever one the + // workspace had focused when it was last in view + if let Some(window_id) = notification.triggered_by.window_id() + && let Ok(workspace) = wm.focused_workspace_mut() + && let Err(error) = workspace.focus_container_by_window(window_id) + { + tracing::debug!("not focusing window {window_id} on reconciliation: {error}"); + } + + if let Some(monitor) = wm.focused_monitor_mut() { monitor.load_focused_workspace(mouse_follows_focus)?; } }