Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions adapters/macos/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSView>,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion adapters/macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion adapters/macos/src/subclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<(&'static AnyClass, &'static AnyClass)>> = Mutex::new(Vec::new());

Expand Down Expand Up @@ -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 {
Expand Down