From 450f8f425f7636f5c5f2cac8d6015532eca7b1e5 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Mon, 16 Sep 2024 23:13:58 +0800 Subject: [PATCH 1/2] fix: ignore focus events from windows that aren't the foreground window --- .../common/events/handle_window_focused.rs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/wm/src/common/events/handle_window_focused.rs b/packages/wm/src/common/events/handle_window_focused.rs index 842f082a0..08ea167fa 100644 --- a/packages/wm/src/common/events/handle_window_focused.rs +++ b/packages/wm/src/common/events/handle_window_focused.rs @@ -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}, @@ -19,18 +22,19 @@ 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(()); - } + info!("Window focused {}", window.native().title()?); // Handle overriding focus on close/minimize. After a window is closed // or minimized, the OS or the closed application might automatically From ea09f533231b141f1ad8921042eb109e026bc485 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Mon, 16 Sep 2024 23:36:40 +0800 Subject: [PATCH 2/2] refactor: remove debug log --- packages/wm/src/common/events/handle_window_focused.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wm/src/common/events/handle_window_focused.rs b/packages/wm/src/common/events/handle_window_focused.rs index 08ea167fa..26a3efac5 100644 --- a/packages/wm/src/common/events/handle_window_focused.rs +++ b/packages/wm/src/common/events/handle_window_focused.rs @@ -34,7 +34,7 @@ pub fn handle_window_focused( } // TODO: Log window details. - info!("Window focused {}", window.native().title()?); + info!("Window focused"); // Handle overriding focus on close/minimize. After a window is closed // or minimized, the OS or the closed application might automatically