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)?; } }