diff --git a/adapters/macos/src/adapter.rs b/adapters/macos/src/adapter.rs index 86b4b0073..ec769a7e1 100644 --- a/adapters/macos/src/adapter.rs +++ b/adapters/macos/src/adapter.rs @@ -23,6 +23,19 @@ use std::{ffi::c_void, ptr::null_mut, rc::Rc}; const PLACEHOLDER_ROOT_ID: NodeId = NodeId(0); +/// See [`Adapter::activation_state`]. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ActivationState { + /// No assistive technology has activated the adapter yet. + Inactive, + /// Activated while [`ActivationHandler::request_initial_tree`] returned + /// `None`; the next update passed to [`Adapter::update_if_active`] must + /// contain a full tree. + Placeholder, + /// The tree is live. + Active, +} + enum State { Inactive { view: WeakId, @@ -144,6 +157,17 @@ impl Adapter { } } + /// The adapter's current activation state. This lets a host whose + /// [`ActivationHandler::request_initial_tree`] returns `None` know when + /// the full tree is due without tracking activation itself. + pub fn activation_state(&self) -> ActivationState { + match &self.state { + State::Inactive { .. } => ActivationState::Inactive, + State::Placeholder { .. } => ActivationState::Placeholder, + State::Active(_) => ActivationState::Active, + } + } + /// Update the tree state based on whether the window is focused. /// /// If a [`QueuedEvents`] instance is returned, the caller must call diff --git a/adapters/macos/src/lib.rs b/adapters/macos/src/lib.rs index 5b795424e..9810ab34a 100644 --- a/adapters/macos/src/lib.rs +++ b/adapters/macos/src/lib.rs @@ -11,7 +11,7 @@ mod node; mod util; mod adapter; -pub use adapter::Adapter; +pub use adapter::{ActivationState, Adapter}; mod event; pub use event::QueuedEvents; diff --git a/adapters/macos/src/subclass.rs b/adapters/macos/src/subclass.rs index a873f7c85..a77ca18ca 100644 --- a/adapters/macos/src/subclass.rs +++ b/adapters/macos/src/subclass.rs @@ -22,7 +22,7 @@ use objc2_app_kit::{NSView, NSWindow}; use objc2_foundation::{NSArray, NSObject, NSPoint}; use std::{cell::RefCell, ffi::c_void, sync::Mutex}; -use crate::{Adapter, event::QueuedEvents}; +use crate::{ActivationState, Adapter, event::QueuedEvents}; static SUBCLASSES: Mutex> = Mutex::new(Vec::new()); @@ -254,6 +254,12 @@ impl SubclassingAdapter { let mut state = self.associated.ivars().state.borrow_mut(); state.adapter.update_view_focus_state(is_focused) } + + /// See [`Adapter::activation_state`]. + pub fn activation_state(&self) -> ActivationState { + let state = self.associated.ivars().state.borrow(); + state.adapter.activation_state() + } } impl Drop for SubclassingAdapter {