Implement screen reader announcements via AccessKit
Browse files at this commit1f76dce345153d7da95262773c317446c1f6fc32Parent: e1afa7110 changed files +566 -24
- Cargo.lock +157 -1
- Cargo.toml +4 -2
- src/a11y.rs +292 -0
- src/input/mod.rs +3 -0
- src/lib.rs +2 -0
- src/main.rs +5 -0
- src/niri.rs +17 -0
- src/ui/config_error_notification.rs +11 -4
- src/ui/exit_confirm_dialog.rs +27 -4
- src/ui/hotkey_overlay.rs +48 -13
Cargo.lockmodified+157 -1
| @@ -2,6 +2,54 @@ | |||
| 2 | # It is not intended for manual editing. | 2 | # It is not intended for manual editing. |
| 3 | version = 3 | 3 | version = 3 |
| 4 | 4 | ||
| 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 | + | ||
| 5 | [[package]] | 53 | [[package]] |
| 6 | name = "adler2" | 54 | name = "adler2" |
| 7 | version = "2.0.1" | 55 | version = "2.0.1" |
| @@ -323,6 +371,56 @@ version = "1.1.0" | |||
| 323 | source = "registry+https://github.com/rust-lang/crates.io-index" | 371 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 324 | checksum = "628d228f918ac3b82fe590352cc719d30664a0c13ca3a60266fe02c7132d480a" | 372 | checksum = "628d228f918ac3b82fe590352cc719d30664a0c13ca3a60266fe02c7132d480a" |
| 325 | 373 | ||
| 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 | + | ||
| 326 | [[package]] | 424 | [[package]] |
| 327 | name = "autocfg" | 425 | name = "autocfg" |
| 328 | version = "1.5.0" | 426 | version = "1.5.0" |
| @@ -1059,6 +1157,12 @@ version = "1.0.7" | |||
| 1059 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1157 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1060 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" | 1158 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" |
| 1061 | 1159 | ||
| 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 | + | ||
| 1062 | [[package]] | 1166 | [[package]] |
| 1063 | name = "foreign-types" | 1167 | name = "foreign-types" |
| 1064 | version = "0.5.0" | 1168 | version = "0.5.0" |
| @@ -1584,6 +1688,9 @@ name = "hashbrown" | |||
| 1584 | version = "0.15.5" | 1688 | version = "0.15.5" |
| 1585 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1689 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1586 | checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" | 1690 | checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" |
| 1691 | +dependencies = [ | ||
| 1692 | + "foldhash", | ||
| 1693 | +] | ||
| 1587 | 1694 | ||
| 1588 | [[package]] | 1695 | [[package]] |
| 1589 | name = "heck" | 1696 | name = "heck" |
| @@ -2246,6 +2353,8 @@ dependencies = [ | |||
| 2246 | name = "niri" | 2353 | name = "niri" |
| 2247 | version = "25.5.1" | 2354 | version = "25.5.1" |
| 2248 | dependencies = [ | 2355 | dependencies = [ |
| 2356 | + "accesskit", | ||
| 2357 | + "accesskit_unix", | ||
| 2249 | "anyhow", | 2358 | "anyhow", |
| 2250 | "approx 0.5.1", | 2359 | "approx 0.5.1", |
| 2251 | "arrayvec", | 2360 | "arrayvec", |
| @@ -3030,6 +3139,16 @@ version = "1.2.3" | |||
| 3030 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3139 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3031 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" | 3140 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" |
| 3032 | 3141 | ||
| 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 | + | ||
| 3033 | [[package]] | 3152 | [[package]] |
| 3034 | name = "quick-xml" | 3153 | name = "quick-xml" |
| 3035 | version = "0.37.5" | 3154 | version = "0.37.5" |
| @@ -4215,7 +4334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 4215 | checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3" | 4334 | checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3" |
| 4216 | dependencies = [ | 4335 | dependencies = [ |
| 4217 | "proc-macro2", | 4336 | "proc-macro2", |
| 4218 | - "quick-xml", | 4337 | + "quick-xml 0.37.5", |
| 4219 | "quote", | 4338 | "quote", |
| 4220 | ] | 4339 | ] |
| 4221 | 4340 | ||
| @@ -4929,6 +5048,30 @@ dependencies = [ | |||
| 4929 | "zvariant", | 5048 | "zvariant", |
| 4930 | ] | 5049 | ] |
| 4931 | 5050 | ||
| 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 | + | ||
| 4932 | [[package]] | 5075 | [[package]] |
| 4933 | name = "zbus_macros" | 5076 | name = "zbus_macros" |
| 4934 | version = "5.9.0" | 5077 | version = "5.9.0" |
| @@ -4956,6 +5099,19 @@ dependencies = [ | |||
| 4956 | "zvariant", | 5099 | "zvariant", |
| 4957 | ] | 5100 | ] |
| 4958 | 5101 | ||
| 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 | + | ||
| 4959 | [[package]] | 5115 | [[package]] |
| 4960 | name = "zerocopy" | 5116 | name = "zerocopy" |
| 4961 | version = "0.8.26" | 5117 | version = "0.8.26" |
Cargo.tomlmodified+4 -2
| @@ -50,6 +50,8 @@ readme = "README.md" | |||
| 50 | keywords = ["wayland", "compositor", "tiling", "smithay", "wm"] | 50 | keywords = ["wayland", "compositor", "tiling", "smithay", "wm"] |
| 51 | 51 | ||
| 52 | [dependencies] | 52 | [dependencies] |
| 53 | +accesskit = { version = "0.21.0", optional = true } | ||
| 54 | +accesskit_unix = { version = "0.17.0", optional = true } | ||
| 53 | anyhow.workspace = true | 55 | anyhow.workspace = true |
| 54 | arrayvec = "0.7.6" | 56 | arrayvec = "0.7.6" |
| 55 | async-channel = "2.5.0" | 57 | async-channel = "2.5.0" |
| @@ -124,8 +126,8 @@ xshell = "0.2.7" | |||
| 124 | 126 | ||
| 125 | [features] | 127 | [features] |
| 126 | default = ["dbus", "systemd", "xdp-gnome-screencast"] | 128 | default = ["dbus", "systemd", "xdp-gnome-screencast"] |
| 127 | -# Enables D-Bus support (serve various freedesktop and GNOME interfaces, power button handling). | 129 | +# Enables D-Bus support (serve various freedesktop and GNOME interfaces, accessibility tree, power button handling). |
| 128 | -dbus = ["dep:zbus", "dep:async-io", "dep:url"] | 130 | +dbus = ["dep:zbus", "dep:async-io", "dep:url", "dep:accesskit", "dep:accesskit_unix"] |
| 129 | # Enables systemd integration (global environment, apps in transient scopes). | 131 | # Enables systemd integration (global environment, apps in transient scopes). |
| 130 | systemd = ["dbus"] | 132 | systemd = ["dbus"] |
| 131 | # Enables screencasting support through xdg-desktop-portal-gnome. | 133 | # 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 { | |||
| 1842 | Action::ShowHotkeyOverlay => { | 1842 | Action::ShowHotkeyOverlay => { |
| 1843 | if self.niri.hotkey_overlay.show() { | 1843 | if self.niri.hotkey_overlay.show() { |
| 1844 | self.niri.queue_redraw_all(); | 1844 | self.niri.queue_redraw_all(); |
| 1845 | + | ||
| 1846 | + #[cfg(feature = "dbus")] | ||
| 1847 | + self.niri.a11y_announce_hotkey_overlay(); | ||
| 1845 | } | 1848 | } |
| 1846 | } | 1849 | } |
| 1847 | Action::MoveWorkspaceToMonitorLeft => { | 1850 | Action::MoveWorkspaceToMonitorLeft => { |
src/lib.rsmodified+2 -0
| @@ -1,6 +1,8 @@ | |||
| 1 | #[macro_use] | 1 | #[macro_use] |
| 2 | extern crate tracing; | 2 | extern crate tracing; |
| 3 | 3 | ||
| 4 | +#[cfg(feature = "dbus")] | ||
| 5 | +pub mod a11y; | ||
| 4 | pub mod animation; | 6 | pub mod animation; |
| 5 | pub mod backend; | 7 | pub mod backend; |
| 6 | pub mod cli; | 8 | pub mod cli; |
src/main.rsmodified+5 -0
| @@ -218,6 +218,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | |||
| 218 | #[cfg(feature = "dbus")] | 218 | #[cfg(feature = "dbus")] |
| 219 | dbus::DBusServers::start(&mut state, cli.session); | 219 | dbus::DBusServers::start(&mut state, cli.session); |
| 220 | 220 | ||
| 221 | + #[cfg(feature = "dbus")] | ||
| 222 | + if cli.session { | ||
| 223 | + state.niri.a11y.start(); | ||
| 224 | + } | ||
| 225 | + | ||
| 221 | if env::var_os("NIRI_DISABLE_SYSTEM_MANAGER_NOTIFY").map_or(true, |x| x != "1") { | 226 | if env::var_os("NIRI_DISABLE_SYSTEM_MANAGER_NOTIFY").map_or(true, |x| x != "1") { |
| 222 | // Notify systemd we're ready. | 227 | // Notify systemd we're ready. |
| 223 | if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) { | 228 | 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; | |||
| 110 | use smithay::wayland::xdg_activation::XdgActivationState; | 110 | use smithay::wayland::xdg_activation::XdgActivationState; |
| 111 | use smithay::wayland::xdg_foreign::XdgForeignState; | 111 | use smithay::wayland::xdg_foreign::XdgForeignState; |
| 112 | 112 | ||
| 113 | +#[cfg(feature = "dbus")] | ||
| 114 | +use crate::a11y::A11y; | ||
| 113 | use crate::animation::Clock; | 115 | use crate::animation::Clock; |
| 114 | use crate::backend::tty::SurfaceDmabufFeedback; | 116 | use crate::backend::tty::SurfaceDmabufFeedback; |
| 115 | use crate::backend::{Backend, Headless, RenderResult, Tty, Winit}; | 117 | use crate::backend::{Backend, Headless, RenderResult, Tty, Winit}; |
| @@ -390,6 +392,8 @@ pub struct Niri { | |||
| 390 | #[cfg(feature = "dbus")] | 392 | #[cfg(feature = "dbus")] |
| 391 | pub a11y_keyboard_monitor: Option<crate::dbus::freedesktop_a11y::KeyboardMonitor>, | 393 | pub a11y_keyboard_monitor: Option<crate::dbus::freedesktop_a11y::KeyboardMonitor>, |
| 392 | #[cfg(feature = "dbus")] | 394 | #[cfg(feature = "dbus")] |
| 395 | + pub a11y: A11y, | ||
| 396 | + #[cfg(feature = "dbus")] | ||
| 393 | pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>, | 397 | pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>, |
| 394 | 398 | ||
| 395 | pub ipc_server: Option<IpcServer>, | 399 | pub ipc_server: Option<IpcServer>, |
| @@ -760,6 +764,10 @@ impl State { | |||
| 760 | self.refresh_ipc_outputs(); | 764 | self.refresh_ipc_outputs(); |
| 761 | self.ipc_refresh_layout(); | 765 | self.ipc_refresh_layout(); |
| 762 | self.ipc_refresh_keyboard_layout_index(); | 766 | 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(); | ||
| 763 | } | 771 | } |
| 764 | 772 | ||
| 765 | fn notify_blocker_cleared(&mut self) { | 773 | fn notify_blocker_cleared(&mut self) { |
| @@ -1326,6 +1334,10 @@ impl State { | |||
| 1326 | Err(()) => { | 1334 | Err(()) => { |
| 1327 | self.niri.config_error_notification.show(); | 1335 | self.niri.config_error_notification.show(); |
| 1328 | self.niri.queue_redraw_all(); | 1336 | self.niri.queue_redraw_all(); |
| 1337 | + | ||
| 1338 | + #[cfg(feature = "dbus")] | ||
| 1339 | + self.niri.a11y_announce_config_error(); | ||
| 1340 | + | ||
| 1329 | return; | 1341 | return; |
| 1330 | } | 1342 | } |
| 1331 | }; | 1343 | }; |
| @@ -2462,6 +2474,9 @@ impl Niri { | |||
| 2462 | 2474 | ||
| 2463 | let exit_confirm_dialog = ExitConfirmDialog::new(animation_clock.clone(), config.clone()); | 2475 | let exit_confirm_dialog = ExitConfirmDialog::new(animation_clock.clone(), config.clone()); |
| 2464 | 2476 | ||
| 2477 | + #[cfg(feature = "dbus")] | ||
| 2478 | + let a11y = A11y::new(event_loop.clone()); | ||
| 2479 | + | ||
| 2465 | event_loop | 2480 | event_loop |
| 2466 | .insert_source( | 2481 | .insert_source( |
| 2467 | Timer::from_duration(Duration::from_secs(1)), | 2482 | Timer::from_duration(Duration::from_secs(1)), |
| @@ -2661,6 +2676,8 @@ impl Niri { | |||
| 2661 | #[cfg(feature = "dbus")] | 2676 | #[cfg(feature = "dbus")] |
| 2662 | a11y_keyboard_monitor: None, | 2677 | a11y_keyboard_monitor: None, |
| 2663 | #[cfg(feature = "dbus")] | 2678 | #[cfg(feature = "dbus")] |
| 2679 | + a11y, | ||
| 2680 | + #[cfg(feature = "dbus")] | ||
| 2664 | inhibit_power_key_fd: None, | 2681 | inhibit_power_key_fd: None, |
| 2665 | 2682 | ||
| 2666 | ipc_server, | 2683 | ipc_server, |
src/ui/config_error_notification.rsmodified+11 -4
| @@ -20,9 +20,6 @@ use crate::render_helpers::renderer::NiriRenderer; | |||
| 20 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; | 20 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| 21 | use crate::utils::{output_size, to_physical_precise_round}; | 21 | use crate::utils::{output_size, to_physical_precise_round}; |
| 22 | 22 | ||
| 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."; | ||
| 26 | const PADDING: i32 = 8; | 23 | const PADDING: i32 = 8; |
| 27 | const FONT: &str = "sans 14px"; | 24 | const FONT: &str = "sans 14px"; |
| 28 | const BORDER: i32 = 4; | 25 | const BORDER: i32 = 4; |
| @@ -186,7 +183,7 @@ fn render( | |||
| 186 | 183 | ||
| 187 | let padding: i32 = to_physical_precise_round(scale, PADDING); | 184 | let padding: i32 = to_physical_precise_round(scale, PADDING); |
| 188 | 185 | ||
| 189 | - let mut text = String::from(TEXT); | 186 | + let mut text = error_text(true); |
| 190 | let mut border_color = (1., 0.3, 0.3); | 187 | let mut border_color = (1., 0.3, 0.3); |
| 191 | if let Some(path) = created_path { | 188 | if let Some(path) = created_path { |
| 192 | text = format!( | 189 | text = format!( |
| @@ -249,3 +246,13 @@ fn render( | |||
| 249 | 246 | ||
| 250 | Ok(buffer) | 247 | Ok(buffer) |
| 251 | } | 248 | } |
| 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 | |||
| 23 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; | 23 | use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement}; |
| 24 | use crate::utils::{output_size, to_physical_precise_round}; | 24 | use crate::utils::{output_size, to_physical_precise_round}; |
| 25 | 25 | ||
| 26 | -const TEXT: &str = "Are you sure you want to exit niri?\n\n\ | 26 | +const KEY_NAME: &str = "Enter"; |
| 27 | - Press <span face='mono' bgcolor='#2C2C2C'> Enter </span> to confirm."; | ||
| 28 | const PADDING: i32 = 16; | 27 | const PADDING: i32 = 16; |
| 29 | const FONT: &str = "sans 14px"; | 28 | const FONT: &str = "sans 14px"; |
| 30 | const BORDER: i32 = 8; | 29 | const BORDER: i32 = 8; |
| @@ -228,6 +227,8 @@ impl ExitConfirmDialog { | |||
| 228 | fn render(scale: f64) -> anyhow::Result<MemoryBuffer> { | 227 | fn render(scale: f64) -> anyhow::Result<MemoryBuffer> { |
| 229 | let _span = tracy_client::span!("exit_confirm_dialog::render"); | 228 | let _span = tracy_client::span!("exit_confirm_dialog::render"); |
| 230 | 229 | ||
| 230 | + let markup = text(true); | ||
| 231 | + | ||
| 231 | let padding: i32 = to_physical_precise_round(scale, PADDING); | 232 | let padding: i32 = to_physical_precise_round(scale, PADDING); |
| 232 | 233 | ||
| 233 | let mut font = FontDescription::from_string(FONT); | 234 | let mut font = FontDescription::from_string(FONT); |
| @@ -239,7 +240,7 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> { | |||
| 239 | layout.context().set_round_glyph_positions(false); | 240 | layout.context().set_round_glyph_positions(false); |
| 240 | layout.set_font_description(Some(&font)); | 241 | layout.set_font_description(Some(&font)); |
| 241 | layout.set_alignment(Alignment::Center); | 242 | layout.set_alignment(Alignment::Center); |
| 242 | - layout.set_markup(TEXT); | 243 | + layout.set_markup(&markup); |
| 243 | 244 | ||
| 244 | let (mut width, mut height) = layout.pixel_size(); | 245 | let (mut width, mut height) = layout.pixel_size(); |
| 245 | width += padding * 2; | 246 | width += padding * 2; |
| @@ -255,7 +256,7 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> { | |||
| 255 | layout.context().set_round_glyph_positions(false); | 256 | layout.context().set_round_glyph_positions(false); |
| 256 | layout.set_font_description(Some(&font)); | 257 | layout.set_font_description(Some(&font)); |
| 257 | layout.set_alignment(Alignment::Center); | 258 | layout.set_alignment(Alignment::Center); |
| 258 | - layout.set_markup(TEXT); | 259 | + layout.set_markup(&markup); |
| 259 | 260 | ||
| 260 | cr.set_source_rgb(1., 1., 1.); | 261 | cr.set_source_rgb(1., 1., 1.); |
| 261 | pangocairo::functions::show_layout(&cr, &layout); | 262 | pangocairo::functions::show_layout(&cr, &layout); |
| @@ -282,3 +283,25 @@ fn render(scale: f64) -> anyhow::Result<MemoryBuffer> { | |||
| 282 | 283 | ||
| 283 | Ok(buffer) | 284 | Ok(buffer) |
| 284 | } | 285 | } |
| 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 @@ | |||
| 1 | use std::cell::RefCell; | 1 | use std::cell::RefCell; |
| 2 | use std::cmp::max; | 2 | use std::cmp::max; |
| 3 | use std::collections::HashMap; | 3 | use std::collections::HashMap; |
| 4 | +use std::fmt::Write as _; | ||
| 4 | use std::iter::zip; | 5 | use std::iter::zip; |
| 5 | use std::rc::Rc; | 6 | use std::rc::Rc; |
| 6 | 7 | ||
| @@ -123,6 +124,32 @@ impl HotkeyOverlay { | |||
| 123 | 124 | ||
| 124 | Some(PrimaryGpuTextureRenderElement(elem)) | 125 | Some(PrimaryGpuTextureRenderElement(elem)) |
| 125 | } | 126 | } |
| 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 | + } | ||
| 126 | } | 153 | } |
| 127 | 154 | ||
| 128 | fn format_bind(binds: &[Bind], action: &Action) -> Option<(Option<Key>, String)> { | 155 | fn format_bind(binds: &[Bind], action: &Action) -> Option<(Option<Key>, String)> { |
| @@ -298,7 +325,7 @@ fn render( | |||
| 298 | .into_iter() | 325 | .into_iter() |
| 299 | .filter_map(|action| format_bind(&config.binds.0, action)) | 326 | .filter_map(|action| format_bind(&config.binds.0, action)) |
| 300 | .map(|(key, action)| { | 327 | .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)); |
| 302 | let key = key.as_deref().unwrap_or("(not bound)"); | 329 | let key = key.as_deref().unwrap_or("(not bound)"); |
| 303 | let key = format!(" {key} "); | 330 | let key = format!(" {key} "); |
| 304 | (key, action) | 331 | (key, action) |
| @@ -466,7 +493,7 @@ fn action_name(action: &Action) -> String { | |||
| 466 | } | 493 | } |
| 467 | } | 494 | } |
| 468 | 495 | ||
| 469 | -fn key_name(mod_key: ModKey, key: &Key) -> String { | 496 | +fn key_name(screen_reader: bool, mod_key: ModKey, key: &Key) -> String { |
| 470 | let mut name = String::new(); | 497 | let mut name = String::new(); |
| 471 | 498 | ||
| 472 | let has_comp_mod = key.modifiers.contains(Modifiers::COMPOSITOR); | 499 | let has_comp_mod = key.modifiers.contains(Modifiers::COMPOSITOR); |
| @@ -519,7 +546,7 @@ fn key_name(mod_key: ModKey, key: &Key) -> String { | |||
| 519 | } | 546 | } |
| 520 | 547 | ||
| 521 | let pretty = match key.trigger { | 548 | 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)), |
| 523 | Trigger::MouseLeft => String::from("Mouse Left"), | 550 | Trigger::MouseLeft => String::from("Mouse Left"), |
| 524 | Trigger::MouseRight => String::from("Mouse Right"), | 551 | Trigger::MouseRight => String::from("Mouse Right"), |
| 525 | Trigger::MouseMiddle => String::from("Mouse Middle"), | 552 | Trigger::MouseMiddle => String::from("Mouse Middle"), |
| @@ -539,16 +566,24 @@ fn key_name(mod_key: ModKey, key: &Key) -> String { | |||
| 539 | name | 566 | name |
| 540 | } | 567 | } |
| 541 | 568 | ||
| 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 | + | ||
| 543 | let name = match name { | 586 | let name = match name { |
| 544 | - "slash" => "/", | ||
| 545 | - "comma" => ",", | ||
| 546 | - "period" => ".", | ||
| 547 | - "minus" => "-", | ||
| 548 | - "equal" => "=", | ||
| 549 | - "grave" => "`", | ||
| 550 | - "bracketleft" => "[", | ||
| 551 | - "bracketright" => "]", | ||
| 552 | "Next" => "Page Down", | 587 | "Next" => "Page Down", |
| 553 | "Prior" => "Page Up", | 588 | "Prior" => "Page Up", |
| 554 | "Print" => "PrtSc", | 589 | "Print" => "PrtSc", |
| @@ -574,7 +609,7 @@ mod tests { | |||
| 574 | fn check(config: &str, action: Action) -> String { | 609 | fn check(config: &str, action: Action) -> String { |
| 575 | let config = Config::parse("test.kdl", config).unwrap(); | 610 | let config = Config::parse("test.kdl", config).unwrap(); |
| 576 | if let Some((key, title)) = format_bind(&config.binds.0, &action) { | 611 | 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)); |
| 578 | let key = key.as_deref().unwrap_or("(not bound)"); | 613 | let key = key.as_deref().unwrap_or("(not bound)"); |
| 579 | format!(" {key} : {title}") | 614 | format!(" {key} : {title}") |
| 580 | } else { | 615 | } else { |