event_loop, a11y, text_shaping: AccessKit AT-SPI2 bridge, cross-app clipboard, xdg-activation, HarfBuzz shaping, multi-touch hooks
Five orthogonal capabilities land together because they share the same `try_run` plumbing: an optional global is bound at startup, a piece of state is added to `AppData`, the run-loop iteration drains an inbox / pushes a frame snapshot, and the public surface gains a small set of opt-in `App` hooks. Nothing here breaks an existing app — every new path degrades to a no-op when the compositor does not advertise the relevant global or when the platform adapter cannot start. AT-SPI2 accessibility via AccessKit. A new `src/a11y/` module owns the platform adapter and the inbound `ActionRequest` channel. `A11yState::try_new` constructs an `accesskit_unix::Adapter`; when the AT-SPI2 daemon is not on the session bus (headless CI, locked-down compositors) the constructor returns `None` and the rest of the pipeline runs unchanged. After every successful `draw_frame`, the run loop builds a fresh `accesskit::TreeUpdate` from `widget_rects` and pushes it through the adapter — main surface plus every visible overlay, each translated to global coordinates via `surface_offset_for` so screen readers report positions in the same frame the user sees. Buttons / toggles / checkboxes / radios / list items / sliders / text edits map to the matching `Role`s; `Click` and `Focus` actions are advertised on every interactive node; inbound action requests are drained at the top of each iteration and translated into a synthetic press / focus on the matching widget. The integration is documented as best-effort in `docs/architecture.md` under "Known gaps and non-goals": hierarchical nesting, per-widget accessible names, live regions and `Action::SetValue` are listed as the natural follow-ups that the foundation now supports but does not yet wire. Cross-application clipboard via `wl_data_device_manager`. A new `src/event_loop/data_device.rs` bridges the existing process-local `clipboard: String` to the Wayland selection. Outbound (Ctrl+C / Cut): after the local clipboard is populated, `publish_clipboard_selection` creates a `CopyPasteSource` offering `text/plain;charset=utf-8` and installs it as the seat's selection; `DataSourceHandler::send` writes the cached string into the fd the peer hands us. Inbound (Ctrl+V from another app): `DataDeviceHandler::selection` asks for the offered text via `WlDataOffer::receive`, spawns a tiny worker thread to drain the read pipe with a 16 MiB cap to prevent paste-bomb DoS, and posts the result back through an `mpsc::Sender` that the run loop drains each iteration into `data.clipboard`. The `clipboard:` field's doc-comment is updated to reflect the new behaviour: process-local when the compositor does not advertise the global, synchronised with the seat selection otherwise. External drag-and-drop reception. The same `data_device` module handles `DragOffer` enter / motion / leave / drop_performed: `on_drop_motion( x, y )` fires while the drag hovers over the surface, `on_drop_leave()` when it withdraws without dropping, and `on_drop_received( x, y, mime, text )` when an external payload (`text/uri-list`, `text/plain`, …) is released on top of an ltk window. The receive path reuses the same worker-thread / channel pattern as the clipboard so the run loop never blocks on the read fd. Three new `App` hooks expose the events with no-op defaults; apps that ignore them get the previous behaviour. `xdg-activation-v1`. The global is bound optionally; when it is present, `try_run` reads `$XDG_ACTIVATION_TOKEN` from the environment, removes it immediately (single-use; preventing leaks into child processes) and stashes it on `AppData::activation_token_pending`. After the first successful configure of the main surface — the earliest point at which `xdg_activation_v1.activate` is meaningful — the token is consumed once and the surface raised to focus. Compositors without the global leave `activation_state` as `None` and the inbound path silently degrades. An `App::request_activation_token` outbound path is reserved on the trait but not yet exercised here. HarfBuzz shaping. A new `src/text_shaping.rs::shape_line` drives both renderers: the logical-order string is run through `unicode-bidi`, split into per-font sub-runs, and shaped through `rustybuzz`. Each `PositionedGlyph` carries the per-font `glyph_id`, the visual advance and the ink offsets — exactly what `fontdue::Font::rasterize_indexed` needs to render Arabic connected forms, Devanagari clusters and CJK shaped glyphs correctly. The GLES atlas is re-keyed on `(glyph_id, size_bits, font_id)` so glyphs from different fonts at the same size no longer collide, and the atlas format is selected per ES profile (`GL_R8` / `GL_RED` on ES3, `GL_LUMINANCE` on ES2) — the fragment shader samples `.r` for both, since `GL_LUMINANCE` replicates the coverage byte into `.r=.g=.b`. Software path follows the same key. New `Cargo.toml` deps: `unicode-bidi = "0.3"`, `rustybuzz = "0.14"`. Multi-touch hooks. `App::on_touch_down / on_touch_move / on_touch_up( id, x, y )` expose the raw `wl_touch.id` of every secondary finger. The first finger to land remains the *primary slot* and is fed through the regular gesture machine (`on_pointer_*`, swipe, scroll, long-press, drag-and-drop). Every additional finger fires the new callbacks instead, leaving the existing single-slot behaviour untouched for apps that do not override them. This is the substrate for app-defined pinch-zoom / two-finger pan; the toolkit itself does not yet ship a built-in pinch gesture (called out in the same "Known gaps" doc section). `event_loop::frame` extracted from `draw/mod.rs`. The `draw_frame` orchestrator and its per-format SHM helper (`pick_shm_format`) move into `src/event_loop/frame.rs`, leaving `draw/` strictly responsible for per-surface paint primitives. The import in `event_loop/run.rs` is rewritten accordingly; `draw/mod.rs` shrinks from 192-line orchestrator to a thin module index. Overlay teardown safety. `AppData::discard_overlay( id )` synchronously removes a destroyed overlay from the map and rewrites every per-device focus that pointed at it (pointer, keyboard, every touch slot), migrating an in-flight long-press drag to the main surface the same way `reconcile_overlays` does. Used by the compositor-driven destruction paths (`PopupHandler::done`, `LayerShellHandler::closed`) where waiting for the next reconcile would leave a window in which `surface()` / `surface_mut()` panic. The non-panicking siblings `try_surface` / `try_surface_mut` are added for callers on async dispatch paths (IME `Done`, tooltip arm) that may race a teardown. Miscellaneous. CI: `master` → `main` to match the actual default branch. `Makefile` adds `cargo run --example dialog` to the examples target. `src/lib.rs` re-exports `widget::scroll::ScrollAxis` so apps can configure a `scroll()` axis without reaching into a `pub(crate)` module. `Cargo.toml` adds `accesskit = "0.17"` and `accesskit_unix = "0.13"`. `docs/architecture.md` gains the "Known gaps and non-goals" section that enumerates the new capabilities, what still ships flat, and what is deferred (per-widget a11y labels, primary selection, intra-process multi-touch gestures, `wp_fractional_scale_v1`).
This commit is contained in:
155
src/a11y/mod.rs
Normal file
155
src/a11y/mod.rs
Normal file
@@ -0,0 +1,155 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-only
|
||||
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>
|
||||
|
||||
//! AT-SPI2 accessibility via AccessKit.
|
||||
//!
|
||||
//! ltk does not implement the D-Bus AT-SPI2 protocol itself — that is
|
||||
//! delegated to [`accesskit_unix`], which translates a backend-neutral
|
||||
//! [`accesskit::TreeUpdate`] into the corresponding D-Bus calls,
|
||||
//! registers the application against `org.a11y.Bus`, and emits the
|
||||
//! property / state / focus change signals Orca and friends listen
|
||||
//! for. Our job is two-way:
|
||||
//!
|
||||
//! 1. **Outbound**: every frame, after the layout pass has populated
|
||||
//! `widget_rects`, build a fresh [`accesskit::TreeUpdate`] from
|
||||
//! those rects and push it into the adapter through
|
||||
//! [`A11yState::update`]. The runtime calls this from the same
|
||||
//! place that runs `draw_frame`, so the accessible tree is always
|
||||
//! in sync with what the user can see.
|
||||
//!
|
||||
//! 2. **Inbound**: an [`accesskit::ActionRequest`] from an assistive
|
||||
//! technology (Orca pressing the "Default Action" on a button, a
|
||||
//! switch-control device focusing the next node, …) lands on the
|
||||
//! [`ActionForwarder`] running inside the adapter's worker
|
||||
//! thread; the forwarder pushes it through an `mpsc::Sender` into
|
||||
//! the run loop, which drains the channel each iteration and
|
||||
//! translates the request into a synthetic press / focus on the
|
||||
//! target widget.
|
||||
//!
|
||||
//! The adapter is constructed unconditionally — `accesskit_unix`
|
||||
//! never refuses creation, it just stays inactive when no AT client
|
||||
//! attaches to the session bus. Nothing else in the pipeline reads
|
||||
//! the field except the per-frame tree update and the per-iteration
|
||||
//! action inbox drain, so the rest of the runtime is unaware of
|
||||
//! whether an AT is listening or not.
|
||||
|
||||
pub( crate ) mod tree;
|
||||
|
||||
use std::sync::mpsc;
|
||||
|
||||
use accesskit::{ ActionRequest, Rect as A11yRect, TreeUpdate };
|
||||
|
||||
/// Channel carrying inbound action requests from the AccessKit
|
||||
/// adapter thread to the run loop.
|
||||
pub( crate ) type ActionInbox = mpsc::Receiver<ActionRequest>;
|
||||
|
||||
/// Top-level accessibility state owned by `AppData`. Holds the
|
||||
/// platform adapter alongside the receiver half of the action
|
||||
/// channel.
|
||||
pub( crate ) struct A11yState
|
||||
{
|
||||
adapter: accesskit_unix::Adapter,
|
||||
pub( crate ) action_rx: ActionInbox,
|
||||
}
|
||||
|
||||
impl A11yState
|
||||
{
|
||||
/// Bring up the AccessKit adapter. Returns `None` only when we
|
||||
/// reserve the right to refuse creation in the future (currently
|
||||
/// always `Some` — `accesskit_unix::Adapter::new` is infallible
|
||||
/// and stays inactive when no AT client is attached). Keeping
|
||||
/// the `Option` lets us toggle accessibility off at runtime via
|
||||
/// an env var or feature flag without re-plumbing every call
|
||||
/// site.
|
||||
pub( crate ) fn try_new( _app_name: &str, _app_id: &str ) -> Option<Self>
|
||||
{
|
||||
let ( action_tx, action_rx ) = mpsc::channel();
|
||||
let adapter = accesskit_unix::Adapter::new(
|
||||
ActivationStub,
|
||||
ActionForwarder { tx: action_tx },
|
||||
DeactivationStub,
|
||||
);
|
||||
Some( Self { adapter, action_rx } )
|
||||
}
|
||||
|
||||
/// Push a freshly-built tree into the adapter. The closure is
|
||||
/// invoked synchronously **only** when AT-SPI2 is currently
|
||||
/// observing the application (an AT client connected to the
|
||||
/// daemon and queried us at least once), so the cost of
|
||||
/// constructing the tree is paid only when something is actually
|
||||
/// listening.
|
||||
pub( crate ) fn update<F>( &mut self, factory: F )
|
||||
where
|
||||
F: FnOnce() -> TreeUpdate,
|
||||
{
|
||||
self.adapter.update_if_active( factory );
|
||||
}
|
||||
|
||||
/// AT-SPI clients filter by window focus; without it Orca skips
|
||||
/// the surface entirely.
|
||||
pub( crate ) fn set_window_focus( &mut self, focused: bool )
|
||||
{
|
||||
self.adapter.update_window_focus_state( focused );
|
||||
}
|
||||
|
||||
pub( crate ) fn set_window_bounds( &mut self, width: f64, height: f64 )
|
||||
{
|
||||
let r = A11yRect { x0: 0.0, y0: 0.0, x1: width, y1: height };
|
||||
self.adapter.set_root_window_bounds( r, r );
|
||||
}
|
||||
|
||||
#[ allow( dead_code ) ]
|
||||
pub( crate ) fn notify_focus( &mut self, new_focus: accesskit::NodeId )
|
||||
{
|
||||
self.adapter.update_if_active( ||
|
||||
{
|
||||
TreeUpdate
|
||||
{
|
||||
nodes: vec![],
|
||||
tree: None,
|
||||
focus: new_focus,
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/// Activation handler the adapter calls when an assistive technology
|
||||
/// first attaches and asks for the initial tree. We hand back an
|
||||
/// empty root — the first proper update comes from the run loop on
|
||||
/// the very next frame, which is the natural moment to materialise a
|
||||
/// real tree (the widget_rects are populated by then).
|
||||
struct ActivationStub;
|
||||
|
||||
impl accesskit::ActivationHandler for ActivationStub
|
||||
{
|
||||
fn request_initial_tree( &mut self ) -> Option<TreeUpdate>
|
||||
{
|
||||
Some( tree::empty_root() )
|
||||
}
|
||||
}
|
||||
|
||||
/// Action handler that simply forwards every incoming request to the
|
||||
/// main event loop. The translation from `ActionRequest` to a
|
||||
/// synthetic press / focus happens on the main thread so it can
|
||||
/// touch the rest of `AppData` without locking.
|
||||
struct ActionForwarder
|
||||
{
|
||||
tx: mpsc::Sender<ActionRequest>,
|
||||
}
|
||||
|
||||
impl accesskit::ActionHandler for ActionForwarder
|
||||
{
|
||||
fn do_action( &mut self, request: ActionRequest )
|
||||
{
|
||||
let _ = self.tx.send( request );
|
||||
}
|
||||
}
|
||||
|
||||
/// Deactivation handler. AccessKit invokes this when every AT client
|
||||
/// detaches; we have no per-client cleanup so it's a no-op.
|
||||
struct DeactivationStub;
|
||||
|
||||
impl accesskit::DeactivationHandler for DeactivationStub
|
||||
{
|
||||
fn deactivate_accessibility( &mut self ) {}
|
||||
}
|
||||
Reference in New Issue
Block a user