From 8aada8559514a2c2f8fc25917963af2835212517 Mon Sep 17 00:00:00 2001 From: Arnold Loubriat Date: Sun, 18 Jan 2026 20:59:24 +0100 Subject: [PATCH] fix: Emit initial focus event for active descendant node --- platforms/atspi-common/src/adapter.rs | 2 +- platforms/macos/src/adapter.rs | 9 +++------ platforms/windows/src/adapter.rs | 4 ++-- platforms/windows/src/node.rs | 6 +++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/platforms/atspi-common/src/adapter.rs b/platforms/atspi-common/src/adapter.rs index 0406fae4..660d5fc4 100644 --- a/platforms/atspi-common/src/adapter.rs +++ b/platforms/atspi-common/src/adapter.rs @@ -424,7 +424,7 @@ impl Adapter { action_handler: Arc, ) -> Self { let tree = Tree::new(initial_state, is_window_focused); - let focus_id = tree.state().focus_id(); + let focus_id = tree.state().focus().map(|node| node.id()); let context = Context::new(app_context, tree, action_handler, root_window_bounds); context.write_app_context().push_adapter(id, &context); let adapter = Self { diff --git a/platforms/macos/src/adapter.rs b/platforms/macos/src/adapter.rs index 6c8c934c..685765ca 100644 --- a/platforms/macos/src/adapter.rs +++ b/platforms/macos/src/adapter.rs @@ -129,12 +129,9 @@ impl Adapter { Rc::clone(action_handler), placeholder_context.mtm, ); - let result = context - .tree - .borrow() - .state() - .focus_id() - .map(|id| QueuedEvents::new(Rc::clone(&context), vec![focus_event(id)])); + let result = context.tree.borrow().state().focus().map(|node| { + QueuedEvents::new(Rc::clone(&context), vec![focus_event(node.id())]) + }); self.state = State::Active(context); result } diff --git a/platforms/windows/src/adapter.rs b/platforms/windows/src/adapter.rs index b9ce64f1..7dd2afa3 100644 --- a/platforms/windows/src/adapter.rs +++ b/platforms/windows/src/adapter.rs @@ -426,8 +426,8 @@ impl Adapter { let result = context .read_tree() .state() - .focus_id() - .map(|id| QueuedEvents(vec![focus_event(context, id)])); + .focus() + .map(|node| QueuedEvents(vec![focus_event(context, node.id())])); self.state = State::Active(Arc::clone(context)); result } diff --git a/platforms/windows/src/node.rs b/platforms/windows/src/node.rs index a343f762..85954fba 100644 --- a/platforms/windows/src/node.rs +++ b/platforms/windows/src/node.rs @@ -1094,14 +1094,14 @@ impl IRawElementProviderFragmentRoot_Impl for PlatformNode_Impl { fn GetFocus(&self) -> Result { self.with_tree_state(|state| { - if let Some(id) = state.focus_id() { + if let Some(node) = state.focus() { let self_id = if let Some(id) = self.node_id { id } else { state.root_id() }; - if id != self_id { - return Ok(self.relative(id).into()); + if node.id() != self_id { + return Ok(self.relative(node.id()).into()); } } Err(Error::empty())