Skip to content

Commit

Permalink
Make it possible to opt out of accessibility support
Browse files Browse the repository at this point in the history
This is only supported for winit with accesskit right now, with Qt it's
always built-in.

On macOS and Windows accessibility support is practically free. On Linux
it pulls in zbus and async-io.
  • Loading branch information
tronical committed Jun 13, 2023
1 parent 0f0b275 commit d4f61f9
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions api/cpp/CMakeLists.txt
Expand Up @@ -111,6 +111,7 @@ define_cargo_feature(backend-qt "Enable Qt based rendering backend" ON)

define_cargo_feature(experimental "Enable experimental features (no compatibility guarantees)" OFF)
define_cargo_feature(gettext "Enable support of translations using gettext" OFF)
define_cargo_feature(accessibility "Enable integration with operating system provided accessibility APIs" ON)

# Compat options
option(SLINT_FEATURE_BACKEND_GL_ALL "This feature is an alias for SLINT_FEATURE_BACKEND_WINIT and SLINT_FEATURE_RENDERER_WINIT_FEMTOVG." OFF)
Expand Down
1 change: 1 addition & 0 deletions api/cpp/Cargo.toml
Expand Up @@ -36,6 +36,7 @@ renderer-winit-skia-opengl = ["i-slint-backend-selector/renderer-winit-skia-open
renderer-winit-skia-vulkan = ["i-slint-backend-selector/renderer-winit-skia-vulkan"]
renderer-winit-software = ["i-slint-backend-selector/renderer-winit-software"]
gettext = ["i-slint-core/gettext-rs"]
accessibility = ["i-slint-backend-selector/accessibility"]

experimental = ["i-slint-renderer-skia", "raw-window-handle"]

Expand Down
7 changes: 7 additions & 0 deletions api/rs/slint/Cargo.toml
Expand Up @@ -24,6 +24,7 @@ default = [
"backend-winit",
"renderer-winit-femtovg",
"backend-qt",
"accessibility",
"compat-1-0",
]

Expand Down Expand Up @@ -65,6 +66,12 @@ software-renderer-systemfonts = ["i-slint-core/software-renderer-systemfonts"]
## **Safety** : You must ensure that there is only one single thread that call into the Slint API
unsafe-single-threaded = ["i-slint-core/unsafe-single-threaded"]

## Enable integration with operating system provided accessibility APIs (default: enabled)
##
## Enabling this feature will try to expose the tree of UI elements to OS provided accessibility
## APIs to support screen readers and other assistive technologies.
accessibility = ["i-slint-backend-selector/accessibility"]

#! ### Backends

#! Slint needs a backend that will act as liaison between Slint and the OS.
Expand Down
1 change: 1 addition & 0 deletions internal/backends/selector/Cargo.toml
Expand Up @@ -26,6 +26,7 @@ renderer-winit-skia-vulkan = ["i-slint-backend-winit/renderer-winit-skia-vulkan"
renderer-winit-software = ["i-slint-backend-winit/renderer-winit-software"]

rtti = ["i-slint-backend-winit?/rtti", "i-slint-backend-qt?/rtti"]
accessibility = ["i-slint-backend-winit?/accessibility"]

[dependencies]
i-slint-core = { version = "=1.0.3", path = "../../../internal/core", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions internal/backends/winit/Cargo.toml
Expand Up @@ -26,6 +26,7 @@ renderer-winit-skia = ["i-slint-renderer-skia"]
renderer-winit-skia-opengl = ["renderer-winit-skia", "i-slint-renderer-skia/opengl"]
renderer-winit-skia-vulkan = ["renderer-winit-skia", "i-slint-renderer-skia/vulkan"]
renderer-winit-software = ["softbuffer", "imgref", "rgb", "i-slint-core/software-renderer-systemfonts"]
accessibility = ["accesskit", "accesskit_winit"]
rtti = ["i-slint-core/rtti"]
default = []

Expand Down Expand Up @@ -69,8 +70,8 @@ wasm-bindgen = { version = "0.2" }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
glutin = { version = "0.30", optional = true, default-features = false, features = ["egl", "wgl"] }
glutin-winit = { version = "0.3.0", optional = true, default-features = false, features = ["egl", "wgl"] }
accesskit = { version = "0.11.0" }
accesskit_winit = { version = "0.14.0" }
accesskit = { version = "0.11.0", optional = true }
accesskit_winit = { version = "0.14.0", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
# For GL rendering
Expand Down
1 change: 1 addition & 0 deletions internal/backends/winit/build.rs
Expand Up @@ -7,5 +7,6 @@ fn main() {
// Setup cfg aliases
cfg_aliases! {
enable_skia_renderer: { any(feature = "renderer-winit-skia", feature = "renderer-winit-skia-opengl", feature = "renderer-winit-skia-vulkan")},
enable_accesskit: { all(feature = "accessibility", not(target_arch = "wasm32")) },
}
}
4 changes: 2 additions & 2 deletions internal/backends/winit/event_loop.rs
Expand Up @@ -502,9 +502,9 @@ pub fn run() -> Result<(), corelib::platform::PlatformError> {
match event {
Event::WindowEvent { event, window_id } => {
if let Some(window) = window_by_id(window_id) {
#[cfg(target_arch = "wasm32")]
#[cfg(not(enable_accesskit))]
let process_event = true;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
let process_event =
window.accesskit_adapter.on_event(&window.winit_window(), &event);

Expand Down
2 changes: 1 addition & 1 deletion internal/backends/winit/lib.rs
Expand Up @@ -53,7 +53,7 @@ mod renderer {
pub(crate) mod sw;
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
mod accesskit;

#[cfg(target_arch = "wasm32")]
Expand Down
12 changes: 6 additions & 6 deletions internal/backends/winit/winitwindowadapter.rs
Expand Up @@ -20,9 +20,9 @@ use crate::renderer::WinitCompatibleRenderer;
use const_field_offset::FieldOffsets;

use corelib::component::ComponentRc;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
use corelib::component::ComponentRef;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
use corelib::items::ItemRef;
use corelib::items::{ItemRc, MouseCursor};

Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct WinitWindowAdapter {
#[cfg(target_arch = "wasm32")]
virtual_keyboard_helper: RefCell<Option<super::wasm_input_helper::WasmInputHelper>>,

#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
pub accesskit_adapter: crate::accesskit::AccessKitAdapter,
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl WinitWindowAdapter {
renderer: Box::new(renderer),
#[cfg(target_arch = "wasm32")]
virtual_keyboard_helper: Default::default(),
#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
accesskit_adapter: crate::accesskit::AccessKitAdapter::new(
self_weak.clone(),
&*winit_window,
Expand Down Expand Up @@ -655,11 +655,11 @@ impl WindowAdapterSealed for WinitWindowAdapter {
}

fn handle_focus_change(&self, _old: Option<ItemRc>, _new: Option<ItemRc>) {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
self.accesskit_adapter.handle_focus_change(_new);
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(enable_accesskit)]
fn unregister_component<'a>(
&self,
_component: ComponentRef,
Expand Down
5 changes: 5 additions & 0 deletions internal/interpreter/Cargo.toml
Expand Up @@ -81,6 +81,11 @@ renderer-winit-skia-vulkan = ["i-slint-backend-selector/renderer-winit-skia-vulk
## Must be used in combination with `backend-winit`, `backend-winit-x11`, or `backend-winit-wayland`.
renderer-winit-software = ["i-slint-backend-selector/renderer-winit-software"]

## Enable integration with operating system provided accessibility APIs (default: enabled)
##
## Enabling this feature will try to expose the tree of UI elements to OS provided accessibility
## APIs to support screen readers and other assistive technologies.
accessibility = ["i-slint-backend-selector/accessibility"]

[dependencies]
i-slint-compiler = { version = "=1.0.3", path = "../compiler" }
Expand Down

0 comments on commit d4f61f9

Please sign in to comment.