forge
Explore
Log in

Don't you dare go Hollow

Implement screen reader announcements via AccessKit

Browse files at this commit

1f76dce345153d7da95262773c317446c1f6fc32Ivan MolodetskikhParent: e1afa71
Cargo.lockmodified+157 -1
@@ -2,6 +2,54 @@
22 # It is not intended for manual editing.
33 version = 3
44
5+[[package]]
6+name = "accesskit"
7+version = "0.21.0"
8+source = "registry+https://github.com/rust-lang/crates.io-index"
9+checksum = "9c0690ad6e6f9597b8439bd3c95e8c6df5cd043afd950c6d68f3b37df641e27c"
10+
11+[[package]]
12+name = "accesskit_atspi_common"
13+version = "0.14.0"
14+source = "registry+https://github.com/rust-lang/crates.io-index"
15+checksum = "8fb511e093896d3cae0efba40322087dff59ea322308a3e6edf70f28d22f2607"
16+dependencies = [
17+ "accesskit",
18+ "accesskit_consumer",
19+ "atspi-common",
20+ "serde",
21+ "thiserror 1.0.69",
22+ "zvariant",
23+]
24+
25+[[package]]
26+name = "accesskit_consumer"
27+version = "0.30.0"
28+source = "registry+https://github.com/rust-lang/crates.io-index"
29+checksum = "ec27574c1baeb7747c802a194566b46b602461e81dc4957949580ea8da695038"
30+dependencies = [
31+ "accesskit",
32+ "hashbrown 0.15.5",
33+]
34+
35+[[package]]
36+name = "accesskit_unix"
37+version = "0.17.0"
38+source = "registry+https://github.com/rust-lang/crates.io-index"
39+checksum = "2abbfb16144cca5bb2ea6acad5865b7c1e70d4fa171ceba1a52ea8e78a7515f4"
40+dependencies = [
41+ "accesskit",
42+ "accesskit_atspi_common",
43+ "async-channel",
44+ "async-executor",
45+ "async-task",
46+ "atspi",
47+ "futures-lite",
48+ "futures-util",
49+ "serde",
50+ "zbus",
51+]
52+
553 [[package]]
654 name = "adler2"
755 version = "2.0.1"
@@ -323,6 +371,56 @@ version = "1.1.0"
323371 source = "registry+https://github.com/rust-lang/crates.io-index"
324372 checksum = "628d228f918ac3b82fe590352cc719d30664a0c13ca3a60266fe02c7132d480a"
325373
374+[[package]]
375+name = "atspi"
376+version = "0.25.0"
377+source = "registry+https://github.com/rust-lang/crates.io-index"
378+checksum = "c83247582e7508838caf5f316c00791eee0e15c0bf743e6880585b867e16815c"
379+dependencies = [
380+ "atspi-common",
381+ "atspi-connection",
382+ "atspi-proxies",
383+]
384+
385+[[package]]
386+name = "atspi-common"
387+version = "0.9.0"
388+source = "registry+https://github.com/rust-lang/crates.io-index"
389+checksum = "33dfc05e7cdf90988a197803bf24f5788f94f7c94a69efa95683e8ffe76cfdfb"
390+dependencies = [
391+ "enumflags2",
392+ "serde",
393+ "static_assertions",
394+ "zbus",
395+ "zbus-lockstep",
396+ "zbus-lockstep-macros",
397+ "zbus_names",
398+ "zvariant",
399+]
400+
401+[[package]]
402+name = "atspi-connection"
403+version = "0.9.0"
404+source = "registry+https://github.com/rust-lang/crates.io-index"
405+checksum = "4193d51303d8332304056ae0004714256b46b6635a5c556109b319c0d3784938"
406+dependencies = [
407+ "atspi-common",
408+ "atspi-proxies",
409+ "futures-lite",
410+ "zbus",
411+]
412+
413+[[package]]
414+name = "atspi-proxies"
415+version = "0.9.0"
416+source = "registry+https://github.com/rust-lang/crates.io-index"
417+checksum = "d2eebcb9e7e76f26d0bcfd6f0295e1cd1e6f33bedbc5698a971db8dc43d7751c"
418+dependencies = [
419+ "atspi-common",
420+ "serde",
421+ "zbus",
422+]
423+
326424 [[package]]
327425 name = "autocfg"
328426 version = "1.5.0"
@@ -1059,6 +1157,12 @@ version = "1.0.7"
10591157 source = "registry+https://github.com/rust-lang/crates.io-index"
10601158 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
10611159
1160+[[package]]
1161+name = "foldhash"
1162+version = "0.1.5"
1163+source = "registry+https://github.com/rust-lang/crates.io-index"
1164+checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
1165+
10621166 [[package]]
10631167 name = "foreign-types"
10641168 version = "0.5.0"
@@ -1584,6 +1688,9 @@ name = "hashbrown"
15841688 version = "0.15.5"
15851689 source = "registry+https://github.com/rust-lang/crates.io-index"
15861690 checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
1691+dependencies = [
1692+ "foldhash",
1693+]
15871694
15881695 [[package]]
15891696 name = "heck"
@@ -2246,6 +2353,8 @@ dependencies = [
22462353 name = "niri"
22472354 version = "25.5.1"
22482355 dependencies = [
2356+ "accesskit",
2357+ "accesskit_unix",
22492358 "anyhow",
22502359 "approx 0.5.1",
22512360 "arrayvec",
@@ -3030,6 +3139,16 @@ version = "1.2.3"
30303139 source = "registry+https://github.com/rust-lang/crates.io-index"
30313140 checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
30323141
3142+[[package]]
3143+name = "quick-xml"
3144+version = "0.36.2"
3145+source = "registry+https://github.com/rust-lang/crates.io-index"
3146+checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
3147+dependencies = [
3148+ "memchr",
3149+ "serde",
3150+]
3151+
30333152 [[package]]
30343153 name = "quick-xml"
30353154 version = "0.37.5"
@@ -4215,7 +4334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
42154334 checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3"
42164335 dependencies = [
42174336 "proc-macro2",
4218- "quick-xml",
4337+ "quick-xml 0.37.5",
42194338 "quote",
42204339 ]
42214340
@@ -4929,6 +5048,30 @@ dependencies = [
49295048 "zvariant",
49305049 ]
49315050
5051+[[package]]
5052+name = "zbus-lockstep"
5053+version = "0.5.1"
5054+source = "registry+https://github.com/rust-lang/crates.io-index"
5055+checksum = "29e96e38ded30eeab90b6ba88cb888d70aef4e7489b6cd212c5e5b5ec38045b6"
5056+dependencies = [
5057+ "zbus_xml",
5058+ "zvariant",
5059+]
5060+
5061+[[package]]
5062+name = "zbus-lockstep-macros"
5063+version = "0.5.1"
5064+source = "registry+https://github.com/rust-lang/crates.io-index"
5065+checksum = "dc6821851fa840b708b4cbbaf6241868cabc85a2dc22f426361b0292bfc0b836"
5066+dependencies = [
5067+ "proc-macro2",
5068+ "quote",
5069+ "syn 2.0.106",
5070+ "zbus-lockstep",
5071+ "zbus_xml",
5072+ "zvariant",
5073+]
5074+
49325075 [[package]]
49335076 name = "zbus_macros"
49345077 version = "5.9.0"
@@ -4956,6 +5099,19 @@ dependencies = [
49565099 "zvariant",
49575100 ]
49585101
5102+[[package]]
5103+name = "zbus_xml"
5104+version = "5.0.2"
5105+source = "registry+https://github.com/rust-lang/crates.io-index"
5106+checksum = "589e9a02bfafb9754bb2340a9e3b38f389772684c63d9637e76b1870377bec29"
5107+dependencies = [
5108+ "quick-xml 0.36.2",
5109+ "serde",
5110+ "static_assertions",
5111+ "zbus_names",
5112+ "zvariant",
5113+]
5114+
49595115 [[package]]
49605116 name = "zerocopy"
49615117 version = "0.8.26"
Cargo.tomlmodified+4 -2
@@ -50,6 +50,8 @@ readme = "README.md"
5050 keywords = ["wayland", "compositor", "tiling", "smithay", "wm"]
5151
5252 [dependencies]
53+accesskit = { version = "0.21.0", optional = true }
54+accesskit_unix = { version = "0.17.0", optional = true }
5355 anyhow.workspace = true
5456 arrayvec = "0.7.6"
5557 async-channel = "2.5.0"
@@ -124,8 +126,8 @@ xshell = "0.2.7"
124126
125127 [features]
126128 default = ["dbus", "systemd", "xdp-gnome-screencast"]
127-# Enables D-Bus support (serve various freedesktop and GNOME interfaces, power button handling).
128-dbus = ["dep:zbus", "dep:async-io", "dep:url"]
129+# Enables D-Bus support (serve various freedesktop and GNOME interfaces, accessibility tree, power button handling).
130+dbus = ["dep:zbus", "dep:async-io", "dep:url", "dep:accesskit", "dep:accesskit_unix"]
129131 # Enables systemd integration (global environment, apps in transient scopes).
130132 systemd = ["dbus"]
131133 # Enables screencasting support through xdg-desktop-portal-gnome.
src/a11y.rsadded+292 -0
@@ -0,0 +1,292 @@
1+use std::sync::mpsc;
2+use std::thread;
3+
4+use accesskit::{
5+ ActionHandler, ActionRequest, ActivationHandler, DeactivationHandler, Live, Node, NodeId, Role,
6+ Tree, TreeUpdate,
7+};
8+use accesskit_unix::Adapter;
9+use calloop::LoopHandle;
10+
11+use crate::layout::workspace::WorkspaceId;
12+use crate::niri::{KeyboardFocus, Niri, State};
13+
14+const ID_ROOT: NodeId = NodeId(0);
15+const ID_ANNOUNCEMENT: NodeId = NodeId(1);
16+const ID_SCREENSHOT_UI: NodeId = NodeId(2);
17+const ID_EXIT_CONFIRM_DIALOG: NodeId = NodeId(3);
18+const ID_OVERVIEW: NodeId = NodeId(4);
19+
20+pub struct A11y {
21+ event_loop: LoopHandle<'static, State>,
22+ focus: NodeId,
23+ workspace_id: Option<WorkspaceId>,
24+ last_announcement: String,
25+ to_accesskit: Option<mpsc::SyncSender<TreeUpdate>>,
26+}
27+
28+enum Msg {
29+ InitialTree,
30+ Deactivate,
31+ Action(ActionRequest),
32+}
33+
34+impl A11y {
35+ pub fn new(event_loop: LoopHandle<'static, State>) -> Self {
36+ Self {
37+ event_loop,
38+ focus: ID_ROOT,
39+ workspace_id: None,
40+ last_announcement: String::new(),
41+ to_accesskit: None,
42+ }
43+ }
44+
45+ pub fn start(&mut self) {
46+ let (tx, rx) = calloop::channel::channel();
47+ let (to_accesskit, from_main) = mpsc::sync_channel::<TreeUpdate>(8);
48+
49+ // The adapter has a tendency to deadlock, so put it on a thread for now...
50+ let handler = Handler { tx };
51+ let res = thread::Builder::new()
52+ .name("AccessKit Adapter".to_owned())
53+ .spawn(move || {
54+ let mut adapter = Adapter::new(handler.clone(), handler.clone(), handler);
55+ while let Ok(tree) = from_main.recv() {
56+ let is_focused = tree.focus != ID_ROOT;
57+ adapter.update_if_active(move || tree);
58+ adapter.update_window_focus_state(is_focused);
59+ }
60+ });
61+
62+ match res {
63+ Ok(_handle) => {}
64+ Err(err) => {
65+ warn!("error spawning the AccessKit adapter thread: {err:?}");
66+ return;
67+ }
68+ }
69+
70+ self.event_loop
71+ .insert_source(rx, |e, _, state| match e {
72+ calloop::channel::Event::Msg(msg) => state.niri.on_a11y_msg(msg),
73+ calloop::channel::Event::Closed => (),
74+ })
75+ .unwrap();
76+
77+ self.to_accesskit = Some(to_accesskit);
78+ }
79+
80+ fn update_tree(&mut self, tree: TreeUpdate) {
81+ trace!("updating tree: {tree:?}");
82+ self.focus = tree.focus;
83+
84+ let Some(tx) = &mut self.to_accesskit else {
85+ return;
86+ };
87+ match tx.try_send(tree) {
88+ Ok(()) => {}
89+ Err(mpsc::TrySendError::Full(_)) => {
90+ warn!("AccessKit channel is full, it probably deadlocked; disconnecting");
91+ self.to_accesskit = None;
92+ }
93+ Err(mpsc::TrySendError::Disconnected(_)) => {
94+ warn!("AccessKit channel disconnected");
95+ self.to_accesskit = None;
96+ }
97+ }
98+ }
99+}
100+
101+impl Niri {
102+ pub fn refresh_a11y(&mut self) {
103+ if self.a11y.to_accesskit.is_none() {
104+ return;
105+ }
106+
107+ let _span = tracy_client::span!("refresh_a11y");
108+
109+ let mut announcement = None;
110+ let ws_id = self.layout.active_workspace().map(|ws| ws.id());
111+ if let Some(ws_id) = ws_id {
112+ if self.a11y.workspace_id != Some(ws_id) {
113+ let (_, idx, ws) = self
114+ .layout
115+ .workspaces()
116+ .find(|(_, _, ws)| ws.id() == ws_id)
117+ .unwrap();
118+
119+ let mut buf = format!("Workspace {}", idx + 1);
120+ if let Some(name) = ws.name() {
121+ buf.push(' ');
122+ buf.push_str(name);
123+ }
124+
125+ announcement = Some(buf);
126+ }
127+ }
128+ self.a11y.workspace_id = ws_id;
129+
130+ let focus = self.a11y_focus();
131+ let update_focus = self.a11y.focus != focus;
132+
133+ if !(announcement.is_some() || update_focus) {
134+ return;
135+ }
136+
137+ let mut nodes = Vec::new();
138+
139+ if let Some(mut announcement) = announcement {
140+ // Work around having to change node value for it to get announced.
141+ if announcement == self.a11y.last_announcement {
142+ announcement.push(' ');
143+ }
144+ self.a11y.last_announcement = announcement.clone();
145+
146+ let mut node = Node::new(Role::Label);
147+ node.set_value(announcement);
148+ node.set_live(Live::Polite);
149+ nodes.push((ID_ANNOUNCEMENT, node));
150+ }
151+
152+ let update = TreeUpdate {
153+ nodes,
154+ tree: None,
155+ focus,
156+ };
157+
158+ self.a11y.update_tree(update);
159+ }
160+
161+ pub fn a11y_announce(&mut self, mut announcement: String) {
162+ if self.a11y.to_accesskit.is_none() {
163+ return;
164+ }
165+
166+ let _span = tracy_client::span!("a11y_announce");
167+
168+ // Work around having to change node value for it to get announced.
169+ if announcement == self.a11y.last_announcement {
170+ announcement.push(' ');
171+ }
172+ self.a11y.last_announcement = announcement.clone();
173+
174+ let mut node = Node::new(Role::Label);
175+ node.set_value(announcement);
176+ node.set_live(Live::Polite);
177+
178+ let update = TreeUpdate {
179+ nodes: vec![(ID_ANNOUNCEMENT, node)],
180+ tree: None,
181+ focus: self.a11y.focus,
182+ };
183+
184+ self.a11y.update_tree(update);
185+ }
186+
187+ pub fn a11y_announce_config_error(&mut self) {
188+ if self.a11y.to_accesskit.is_none() {
189+ return;
190+ }
191+
192+ self.a11y_announce(crate::ui::config_error_notification::error_text(false));
193+ }
194+
195+ pub fn a11y_announce_hotkey_overlay(&mut self) {
196+ if self.a11y.to_accesskit.is_none() {
197+ return;
198+ }
199+
200+ self.a11y_announce(self.hotkey_overlay.a11y_text());
201+ }
202+
203+ fn a11y_focus(&self) -> NodeId {
204+ match self.keyboard_focus {
205+ KeyboardFocus::ScreenshotUi => ID_SCREENSHOT_UI,
206+ KeyboardFocus::ExitConfirmDialog => ID_EXIT_CONFIRM_DIALOG,
207+ KeyboardFocus::Overview => ID_OVERVIEW,
208+ _ => ID_ROOT,
209+ }
210+ }
211+
212+ fn on_a11y_msg(&mut self, msg: Msg) {
213+ match msg {
214+ Msg::InitialTree => {
215+ let tree = self.a11y_build_full_tree();
216+ trace!("sending initial tree: {tree:?}");
217+ self.a11y.update_tree(tree);
218+ }
219+ Msg::Deactivate => {
220+ trace!("deactivate");
221+ }
222+ Msg::Action(request) => {
223+ trace!("request: {request:?}");
224+ }
225+ }
226+ }
227+
228+ fn a11y_build_full_tree(&self) -> TreeUpdate {
229+ let mut node = Node::new(Role::Label);
230+ node.set_live(Live::Polite);
231+
232+ let mut screenshot_ui = Node::new(Role::Group);
233+ screenshot_ui.set_label("Screenshot UI");
234+
235+ let exit_confirm_dialog = crate::ui::exit_confirm_dialog::a11y_node();
236+
237+ let mut overview = Node::new(Role::Group);
238+ overview.set_label("Overview");
239+
240+ let mut root = Node::new(Role::Window);
241+ root.set_children(vec![
242+ ID_ANNOUNCEMENT,
243+ ID_SCREENSHOT_UI,
244+ ID_EXIT_CONFIRM_DIALOG,
245+ ID_OVERVIEW,
246+ ]);
247+
248+ let tree = Tree {
249+ root: ID_ROOT,
250+ toolkit_name: Some(String::from("niri")),
251+ toolkit_version: None,
252+ };
253+
254+ let focus = self.a11y_focus();
255+
256+ TreeUpdate {
257+ nodes: vec![
258+ (ID_ROOT, root),
259+ (ID_ANNOUNCEMENT, node),
260+ (ID_SCREENSHOT_UI, screenshot_ui),
261+ (ID_EXIT_CONFIRM_DIALOG, exit_confirm_dialog),
262+ (ID_OVERVIEW, overview),
263+ ],
264+ tree: Some(tree),
265+ focus,
266+ }
267+ }
268+}
269+
270+#[derive(Clone)]
271+struct Handler {
272+ tx: calloop::channel::Sender<Msg>,
273+}
274+
275+impl ActivationHandler for Handler {
276+ fn request_initial_tree(&mut self) -> Option<TreeUpdate> {
277+ let _ = self.tx.send(Msg::InitialTree);
278+ None
279+ }
280+}
281+
282+impl DeactivationHandler for Handler {
283+ fn deactivate_accessibility(&mut self) {
284+ let _ = self.tx.send(Msg::Deactivate);
285+ }
286+}
287+
288+impl ActionHandler for Handler {
289+ fn do_action(&mut self, request: ActionRequest) {
290+ let _ = self.tx.send(Msg::Action(request));
291+ }
292+}
src/input/mod.rsmodified+3 -0
@@ -1842,6 +1842,9 @@ impl State {
18421842 Action::ShowHotkeyOverlay => {
18431843 if self.niri.hotkey_overlay.show() {
18441844 self.niri.queue_redraw_all();
1845+
1846+ #[cfg(feature = "dbus")]
1847+ self.niri.a11y_announce_hotkey_overlay();
18451848 }
18461849 }
18471850 Action::MoveWorkspaceToMonitorLeft => {
src/lib.rsmodified+2 -0
@@ -1,6 +1,8 @@
11 #[macro_use]
22 extern crate tracing;
33
4+#[cfg(feature = "dbus")]
5+pub mod a11y;
46 pub mod animation;
57 pub mod backend;
68 pub mod cli;
src/main.rsmodified+5 -0
@@ -218,6 +218,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
218218 #[cfg(feature = "dbus")]
219219 dbus::DBusServers::start(&mut state, cli.session);
220220
221+ #[cfg(feature = "dbus")]
222+ if cli.session {
223+ state.niri.a11y.start();
224+ }
225+
221226 if env::var_os("NIRI_DISABLE_SYSTEM_MANAGER_NOTIFY").map_or(true, |x| x != "1") {
222227 // Notify systemd we're ready.
223228 if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {
src/niri.rsmodified+17 -0
@@ -110,6 +110,8 @@ use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
110110 use smithay::wayland::xdg_activation::XdgActivationState;
111111 use smithay::wayland::xdg_foreign::XdgForeignState;
112112
113+#[cfg(feature = "dbus")]
114+use crate::a11y::A11y;
113115 use crate::animation::Clock;
114116 use crate::backend::tty::SurfaceDmabufFeedback;
115117 use crate::backend::{Backend, Headless, RenderResult, Tty, Winit};
@@ -390,6 +392,8 @@ pub struct Niri {
390392 #[cfg(feature = "dbus")]
391393 pub a11y_keyboard_monitor: Option<crate::dbus::freedesktop_a11y::KeyboardMonitor>,
392394 #[cfg(feature = "dbus")]
395+ pub a11y: A11y,
396+ #[cfg(feature = "dbus")]
393397 pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,
394398
395399 pub ipc_server: Option<IpcServer>,
@@ -760,6 +764,10 @@ impl State {
760764 self.refresh_ipc_outputs();
761765 self.ipc_refresh_layout();
762766 self.ipc_refresh_keyboard_layout_index();
767+
768+ // Needs to be called after updating the keyboard focus.
769+ #[cfg(feature = "dbus")]
770+ self.niri.refresh_a11y();
763771 }
764772
765773 fn notify_blocker_cleared(&mut self) {
@@ -1326,6 +1334,10 @@ impl State {
13261334 Err(()) => {
13271335 self.niri.config_error_notification.show();
13281336 self.niri.queue_redraw_all();
1337+
1338+ #[cfg(feature = "dbus")]
1339+ self.niri.a11y_announce_config_error();
1340+
13291341 return;
13301342 }
13311343 };
@@ -2462,6 +2474,9 @@ impl Niri {
24622474
24632475 let exit_confirm_dialog = ExitConfirmDialog::new(animation_clock.clone(), config.clone());
24642476
2477+ #[cfg(feature = "dbus")]
2478+ let a11y = A11y::new(event_loop.clone());
2479+
24652480 event_loop
24662481 .insert_source(
24672482 Timer::from_duration(Duration::from_secs(1)),
@@ -2661,6 +2676,8 @@ impl Niri {
26612676 #[cfg(feature = "dbus")]
26622677 a11y_keyboard_monitor: None,
26632678 #[cfg(feature = "dbus")]
2679+ a11y,
2680+ #[cfg(feature = "dbus")]
26642681 inhibit_power_key_fd: None,
26652682
26662683 ipc_server,
src/ui/config_error_notification.rsmodified+11 -4
@@ -20,9 +20,6 @@ use crate::render_helpers::renderer::NiriRenderer;
2020 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
2121 use crate::utils::{output_size, to_physical_precise_round};
2222
23-const TEXT: &str = "Failed to parse the config file. \
24- Please run <span face='monospace' bgcolor='#000000'>niri validate</span> \
25- to see the errors.";
2623 const PADDING: i32 = 8;
2724 const FONT: &str = "sans 14px";
2825 const BORDER: i32 = 4;
@@ -186,7 +183,7 @@ fn render(
186183
187184 let padding: i32 = to_physical_precise_round(scale, PADDING);
188185
189- let mut text = String::from(TEXT);
186+ let mut text = error_text(true);
190187 let mut border_color = (1., 0.3, 0.3);
191188 if let Some(path) = created_path {
192189 text = format!(
@@ -249,3 +246,13 @@ fn render(
249246
250247 Ok(buffer)
251248 }
249+
250+pub fn error_text(markup: bool) -> String {
251+ let command = if markup {
252+ "<span face='monospace' bgcolor='#000000'>niri validate</span>"
253+ } else {
254+ "niri validate"
255+ };
256+
257+ format!("Failed to parse the config file. Please run {command} to see the errors.")
258+}
src/ui/exit_confirm_dialog.rsmodified+27 -4
@@ -23,8 +23,7 @@ use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderEleme
2323 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
2424 use crate::utils::{output_size, to_physical_precise_round};
2525
26-const TEXT: &str = "Are you sure you want to exit niri?\n\n\
27- Press <span face='mono' bgcolor='#2C2C2C'> Enter </span> to confirm.";
26+const KEY_NAME: &str = "Enter";
2827 const PADDING: i32 = 16;
2928 const FONT: &str = "sans 14px";
3029 const BORDER: i32 = 8;
@@ -228,6 +227,8 @@ impl ExitConfirmDialog {
228227 fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
229228 let _span = tracy_client::span!("exit_confirm_dialog::render");
230229
230+ let markup = text(true);
231+
231232 let padding: i32 = to_physical_precise_round(scale, PADDING);
232233
233234 let mut font = FontDescription::from_string(FONT);
@@ -239,7 +240,7 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
239240 layout.context().set_round_glyph_positions(false);
240241 layout.set_font_description(Some(&font));
241242 layout.set_alignment(Alignment::Center);
242- layout.set_markup(TEXT);
243+ layout.set_markup(&markup);
243244
244245 let (mut width, mut height) = layout.pixel_size();
245246 width += padding * 2;
@@ -255,7 +256,7 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
255256 layout.context().set_round_glyph_positions(false);
256257 layout.set_font_description(Some(&font));
257258 layout.set_alignment(Alignment::Center);
258- layout.set_markup(TEXT);
259+ layout.set_markup(&markup);
259260
260261 cr.set_source_rgb(1., 1., 1.);
261262 pangocairo::functions::show_layout(&cr, &layout);
@@ -282,3 +283,25 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> {
282283
283284 Ok(buffer)
284285 }
286+
287+fn text(markup: bool) -> String {
288+ let key = if markup {
289+ format!("<span face='mono' bgcolor='#2C2C2C'> {KEY_NAME} </span>")
290+ } else {
291+ String::from(KEY_NAME)
292+ };
293+
294+ format!(
295+ "Are you sure you want to exit niri?\n\n\
296+ Press {key} to confirm."
297+ )
298+}
299+
300+#[cfg(feature = "dbus")]
301+pub fn a11y_node() -> accesskit::Node {
302+ let mut node = accesskit::Node::new(accesskit::Role::AlertDialog);
303+ node.set_label("Exit niri");
304+ node.set_description(text(false));
305+ node.set_modal();
306+ node
307+}
src/ui/hotkey_overlay.rsmodified+48 -13
@@ -1,6 +1,7 @@
11 use std::cell::RefCell;
22 use std::cmp::max;
33 use std::collections::HashMap;
4+use std::fmt::Write as _;
45 use std::iter::zip;
56 use std::rc::Rc;
67
@@ -123,6 +124,32 @@ impl HotkeyOverlay {
123124
124125 Some(PrimaryGpuTextureRenderElement(elem))
125126 }
127+
128+ pub fn a11y_text(&self) -> String {
129+ let config = self.config.borrow();
130+ let actions = collect_actions(&config);
131+
132+ let mut buf = String::new();
133+ writeln!(&mut buf, "{TITLE}").unwrap();
134+
135+ for action in actions {
136+ let Some((key, action)) = format_bind(&config.binds.0, action) else {
137+ continue;
138+ };
139+
140+ let key = key.map(|key| key_name(true, self.mod_key, &key));
141+ let key = key.as_deref().unwrap_or("not bound");
142+
143+ let action = match pango::parse_markup(&action, '\0') {
144+ Ok((_attrs, text, _accel)) => text,
145+ Err(_) => action.into(),
146+ };
147+
148+ writeln!(&mut buf, "{key} {action}").unwrap();
149+ }
150+
151+ buf
152+ }
126153 }
127154
128155 fn format_bind(binds: &[Bind], action: &Action) -> Option<(Option<Key>, String)> {
@@ -298,7 +325,7 @@ fn render(
298325 .into_iter()
299326 .filter_map(|action| format_bind(&config.binds.0, action))
300327 .map(|(key, action)| {
301- let key = key.map(|key| key_name(mod_key, &key));
328+ let key = key.map(|key| key_name(false, mod_key, &key));
302329 let key = key.as_deref().unwrap_or("(not bound)");
303330 let key = format!(" {key} ");
304331 (key, action)
@@ -466,7 +493,7 @@ fn action_name(action: &Action) -> String {
466493 }
467494 }
468495
469-fn key_name(mod_key: ModKey, key: &Key) -> String {
496+fn key_name(screen_reader: bool, mod_key: ModKey, key: &Key) -> String {
470497 let mut name = String::new();
471498
472499 let has_comp_mod = key.modifiers.contains(Modifiers::COMPOSITOR);
@@ -519,7 +546,7 @@ fn key_name(mod_key: ModKey, key: &Key) -> String {
519546 }
520547
521548 let pretty = match key.trigger {
522- Trigger::Keysym(keysym) => prettify_keysym_name(&keysym_get_name(keysym)),
549+ Trigger::Keysym(keysym) => prettify_keysym_name(screen_reader, &keysym_get_name(keysym)),
523550 Trigger::MouseLeft => String::from("Mouse Left"),
524551 Trigger::MouseRight => String::from("Mouse Right"),
525552 Trigger::MouseMiddle => String::from("Mouse Middle"),
@@ -539,16 +566,24 @@ fn key_name(mod_key: ModKey, key: &Key) -> String {
539566 name
540567 }
541568
542-fn prettify_keysym_name(name: &str) -> String {
569+fn prettify_keysym_name(screen_reader: bool, name: &str) -> String {
570+ let name = if screen_reader {
571+ name
572+ } else {
573+ match name {
574+ "slash" => "/",
575+ "comma" => ",",
576+ "period" => ".",
577+ "minus" => "-",
578+ "equal" => "=",
579+ "grave" => "`",
580+ "bracketleft" => "[",
581+ "bracketright" => "]",
582+ _ => name,
583+ }
584+ };
585+
543586 let name = match name {
544- "slash" => "/",
545- "comma" => ",",
546- "period" => ".",
547- "minus" => "-",
548- "equal" => "=",
549- "grave" => "`",
550- "bracketleft" => "[",
551- "bracketright" => "]",
552587 "Next" => "Page Down",
553588 "Prior" => "Page Up",
554589 "Print" => "PrtSc",
@@ -574,7 +609,7 @@ mod tests {
574609 fn check(config: &str, action: Action) -> String {
575610 let config = Config::parse("test.kdl", config).unwrap();
576611 if let Some((key, title)) = format_bind(&config.binds.0, &action) {
577- let key = key.map(|key| key_name(ModKey::Super, &key));
612+ let key = key.map(|key| key_name(false, ModKey::Super, &key));
578613 let key = key.as_deref().unwrap_or("(not bound)");
579614 format!(" {key} : {title}")
580615 } else {