From 484ac7be751d4cc6d87ef384562f0c137d86dfbb Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 8 Feb 2024 18:32:11 -0500 Subject: [PATCH] chore: update accesskit --- accessibility/src/id.rs | 33 ++++++++++++++------------------- examples/sctk_todos/Cargo.toml | 2 +- examples/todos/Cargo.toml | 2 +- sctk/src/application.rs | 7 +++---- sctk/src/event_loop/adapter.rs | 9 +++------ sctk/src/event_loop/mod.rs | 13 +++++-------- widget/src/checkbox.rs | 10 ++++------ widget/src/toggler.rs | 10 ++++------ winit/src/application.rs | 23 +++++++---------------- winit/src/multi_window.rs | 7 ++++--- 10 files changed, 46 insertions(+), 70 deletions(-) diff --git a/accessibility/src/id.rs b/accessibility/src/id.rs index d012f4da19..752e51c192 100644 --- a/accessibility/src/id.rs +++ b/accessibility/src/id.rs @@ -1,12 +1,12 @@ //! Widget and Window IDs. +use std::borrow; use std::hash::Hash; use std::sync::atomic::{self, AtomicU64}; -use std::{borrow, num::NonZeroU128}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum A11yId { - Window(NonZeroU128), + Window(u64), Widget(Id), } @@ -20,8 +20,8 @@ pub enum A11yId { // } // } -impl From for A11yId { - fn from(id: NonZeroU128) -> Self { +impl From for A11yId { + fn from(id: u64) -> Self { Self::Window(id) } } @@ -46,8 +46,8 @@ impl IdEq for A11yId { impl From for A11yId { fn from(value: accesskit::NodeId) -> Self { - let val = u128::from(value.0); - if val > u64::MAX as u128 { + let val = u64::from(value.0); + if val > u32::MAX as u64 { Self::Window(value.0) } else { Self::Widget(Id::from(val as u64)) @@ -110,13 +110,11 @@ impl From for Id { } // Not meant to be used directly -impl From for NonZeroU128 { - fn from(val: Id) -> NonZeroU128 { +impl From for u64 { + fn from(val: Id) -> u64 { match &val.0 { - Internal::Unique(id) => NonZeroU128::try_from(*id as u128).unwrap(), - Internal::Custom(id, _) => { - NonZeroU128::try_from(*id as u128).unwrap() - } + Internal::Unique(id) => *id, + Internal::Custom(id, _) => *id, // this is a set id, which is not a valid id and will not ever be converted to a NonZeroU128 // so we panic Internal::Set(_) => { @@ -136,14 +134,11 @@ impl ToString for Id { } } -// XXX WIndow IDs are made unique by adding u64::MAX to them +// XXX WIndow IDs are made unique by adding u32::MAX to them /// get window node id that won't conflict with other node ids for the duration of the program -pub fn window_node_id() -> NonZeroU128 { - std::num::NonZeroU128::try_from( - u64::MAX as u128 - + NEXT_WINDOW_ID.fetch_add(1, atomic::Ordering::Relaxed) as u128, - ) - .unwrap() +pub fn window_node_id() -> u64 { + u32::MAX as u64 + + NEXT_WINDOW_ID.fetch_add(1, atomic::Ordering::Relaxed) as u64 } // TODO refactor to make panic impossible? diff --git a/examples/sctk_todos/Cargo.toml b/examples/sctk_todos/Cargo.toml index fc1b9d0b8f..2797de7ef0 100644 --- a/examples/sctk_todos/Cargo.toml +++ b/examples/sctk_todos/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../..", default-features=false, features = ["async-std", "wayland", "debug"] } +iced = { path = "../..", default-features=false, features = ["async-std", "wayland", "debug", "a11y"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" iced_core.workspace = true diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml index 5926a39a7f..6ce3bbcb49 100644 --- a/examples/todos/Cargo.toml +++ b/examples/todos/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] iced.workspace = true iced_core.workspace = true -iced.features = ["async-std", "debug", "winit"] +iced.features = ["async-std", "debug", "winit", "a11y"] once_cell.workspace = true serde = { version = "1.0", features = ["derive"] } diff --git a/sctk/src/application.rs b/sctk/src/application.rs index 065f386d94..27b47fb9d3 100644 --- a/sctk/src/application.rs +++ b/sctk/src/application.rs @@ -1347,8 +1347,9 @@ where ); let focus = focus .filter(|f_id| window_tree.contains(f_id)) - .map(|id| id.into()); - adapter.adapter.update(TreeUpdate { + .map(|id| id.into()) + .unwrap_or_else(|| tree.root); + adapter.adapter.update_if_active(|| TreeUpdate { nodes: window_tree.into(), tree: Some(tree), focus, @@ -1459,8 +1460,6 @@ where Action::Increment => todo!(), Action::HideTooltip => todo!(), Action::ShowTooltip => todo!(), - Action::InvalidateTree => todo!(), - Action::LoadInlineTextBoxes => todo!(), Action::ReplaceSelectedText => todo!(), Action::ScrollBackward => todo!(), Action::ScrollDown => todo!(), diff --git a/sctk/src/event_loop/adapter.rs b/sctk/src/event_loop/adapter.rs index a185ad9172..ae662f3cac 100644 --- a/sctk/src/event_loop/adapter.rs +++ b/sctk/src/event_loop/adapter.rs @@ -2,10 +2,7 @@ use crate::sctk_event::ActionRequestEvent; use iced_accessibility::{accesskit, accesskit_unix}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::Proxy; -use std::{ - num::NonZeroU128, - sync::{Arc, Mutex}, -}; +use std::sync::{Arc, Mutex}; pub enum A11yWrapper { Enabled, @@ -13,7 +10,7 @@ pub enum A11yWrapper { } pub struct IcedSctkAdapter { - pub(crate) id: NonZeroU128, + pub(crate) id: u64, pub(crate) adapter: accesskit_unix::Adapter, } @@ -22,7 +19,7 @@ pub struct IcedSctkActionHandler { pub(crate) event_list: Arc>>, } impl accesskit::ActionHandler for IcedSctkActionHandler { - fn do_action(&self, request: accesskit::ActionRequest) { + fn do_action(&mut self, request: accesskit::ActionRequest) { let mut event_list = self.event_list.lock().unwrap(); event_list.push(A11yWrapper::Event( crate::sctk_event::ActionRequestEvent { diff --git a/sctk/src/event_loop/mod.rs b/sctk/src/event_loop/mod.rs index e728dd7b95..976891599d 100644 --- a/sctk/src/event_loop/mod.rs +++ b/sctk/src/event_loop/mod.rs @@ -259,9 +259,6 @@ where let event_list = self.a11y_events.clone(); adapter::IcedSctkAdapter { adapter: Adapter::new( - app_id.unwrap_or_else(|| String::from("None")), - "Iced".to_string(), - env!("CARGO_PKG_VERSION").to_string(), move || { event_list .lock() @@ -272,18 +269,18 @@ where node.set_name(name); } let node = node.build(&mut NodeClassSet::lock_global()); + let root = NodeId(node_id); TreeUpdate { - nodes: vec![(NodeId(node_id), node)], - tree: Some(Tree::new(NodeId(node_id))), - focus: None, + nodes: vec![(root, node)], + tree: Some(Tree::new(root)), + focus: root, } }, Box::new(adapter::IcedSctkActionHandler { wl_surface: surface.clone(), event_list: self.a11y_events.clone(), }), - ) - .unwrap(), + ), id: node_id, } } diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index 410f2ee629..c6f1fd26cc 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -392,9 +392,7 @@ where cursor: mouse::Cursor, ) -> iced_accessibility::A11yTree { use iced_accessibility::{ - accesskit::{ - Action, CheckedState, NodeBuilder, NodeId, Rect, Role, - }, + accesskit::{Action, Checked, NodeBuilder, NodeId, Rect, Role}, A11yNode, A11yTree, }; @@ -435,10 +433,10 @@ where } None => {} } - node.set_checked_state(if self.is_checked { - CheckedState::True + node.set_checked(if self.is_checked { + Checked::True } else { - CheckedState::False + Checked::False }); if is_hovered { node.set_hovered(); diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index fba9d63b96..be0880d4dd 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -419,9 +419,7 @@ where cursor: mouse::Cursor, ) -> iced_accessibility::A11yTree { use iced_accessibility::{ - accesskit::{ - Action, CheckedState, NodeBuilder, NodeId, Rect, Role, - }, + accesskit::{Action, Checked, NodeBuilder, NodeId, Rect, Role}, A11yNode, A11yTree, }; @@ -462,10 +460,10 @@ where } None => {} } - node.set_checked_state(if self.is_toggled { - CheckedState::True + node.set_checked(if self.is_toggled { + Checked::True } else { - CheckedState::False + Checked::False }); if is_hovered { node.set_hovered(); diff --git a/winit/src/application.rs b/winit/src/application.rs index 36a39d5cc6..e473177577 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -387,10 +387,11 @@ async fn run_instance( let mut node = NodeBuilder::new(Role::Window); node.set_name(title.clone()); let node = node.build(&mut iced_accessibility::accesskit::NodeClassSet::lock_global()); + let root = NodeId(node_id); TreeUpdate { - nodes: vec![(NodeId(node_id), node)], - tree: Some(Tree::new(NodeId(node_id))), - focus: None, + nodes: vec![(root, node)], + tree: Some(Tree::new(root)), + focus: root, } }, proxy.clone(), @@ -421,17 +422,6 @@ async fn run_instance( )), )); } - event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( - event::MacOS::ReceivedUrl(url), - )) => { - use crate::core::event; - - events.push(Event::PlatformSpecific( - event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( - url, - )), - )); - } event::Event::UserEvent(message) => { match message { UserEventWrapper::Message(m) => messages.push(m), @@ -617,8 +607,9 @@ async fn run_instance( // TODO maybe optimize this? let focus = focus .filter(|f_id| window_tree.contains(f_id)) - .map(|id| id.into()); - adapter.update(TreeUpdate { + .map(|id| id.into()) + .unwrap_or_else(|| tree.root); + adapter.update_if_active(|| TreeUpdate { nodes: window_tree.into(), tree: Some(tree), focus, diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs index 88992bc137..6fe4657620 100644 --- a/winit/src/multi_window.rs +++ b/winit/src/multi_window.rs @@ -377,10 +377,11 @@ async fn run_instance( let mut node = NodeBuilder::new(Role::Window); node.set_name(title.clone()); let node = node.build(&mut iced_accessibility::accesskit::NodeClassSet::lock_global()); + let root = NodeId(node_id); TreeUpdate { - nodes: vec![(NodeId(node_id), node)], - tree: Some(Tree::new(NodeId(node_id))), - focus: None, + nodes: vec![(root, node)], + tree: Some(Tree::new(root)), + focus: root, } }, proxy.clone(),