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.
This commit is contained in:
LGUG2Z committed 2026-10-28 12:29:04 -07:00
1 parent 3e59a2b210
commit 8f768fd4ca
2 files changed
+28

No files matched your search

+16
View File
@@ -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!(
+12
View File
@@ -131,6 +131,18 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> 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)?;
}
}