Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore focus events from windows that aren't the foreground window #725

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/wm/src/common/events/handle_window_focused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use anyhow::Context;
use tracing::info;

use crate::{
common::{platform::NativeWindow, DisplayState},
common::{
platform::{NativeWindow, Platform},
DisplayState,
},
containers::{commands::set_focused_descendant, traits::CommonGetters},
user_config::{UserConfig, WindowRuleEvent},
windows::{commands::run_window_rules, traits::WindowGetters},
Expand All @@ -19,19 +22,20 @@ pub fn handle_window_focused(
let found_window = state.window_from_native(&native_window);

if let Some(window) = found_window {
// Ignore event if window is being hidden by the WM.
if window.display_state() == DisplayState::Hiding {
// Ignore the focus event if:
// 1. Window is being hidden by the WM.
// 2. Focus is already set to the WM's focused container.
// 3. Window is not actually the foreground window.
if window.display_state() == DisplayState::Hiding
|| state.focused_container() == Some(window.clone().into())
|| Platform::foreground_window() != native_window
{
return Ok(());
}

// TODO: Log window details.
info!("Window focused");

// Focus is already set to the WM's focused container.
if state.focused_container() == Some(window.clone().into()) {
return Ok(());
}

// Handle overriding focus on close/minimize. After a window is closed
// or minimized, the OS or the closed application might automatically
// switch focus to a different window. To force focus to go to the WM's
Expand Down