Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,18 @@ Text shows the first 128 KiB of the file, cut at the end of a line, and Markdown
formatted. A file with a zero byte in its first 8,000 bytes isn't text. Page Up, Page Down,
Home, End, Shift+Up, Shift+Down and the mouse wheel scroll it.

Dragging over text selects it, a double click takes a word and a third the line, Ctrl+A takes
all of it, and Ctrl+C copies. To select from the keyboard, F7 turns on caret mode, with a caret
at the start of the text in view. The arrows move it by a character or a line, Ctrl+Left and
Ctrl+Right by a word, Home and End to the ends of the line, and Ctrl+Home and Ctrl+End to the
ends of the text. Shift with any of them selects, Shift+Up and Shift+Down by lines, and a click
moves the caret. While caret mode is on, the arrows don't go to other files and Shift+Up and
Shift+Down don't scroll. Page Up, Page Down and the wheel still scroll without moving the
caret, as in a browser's caret browsing, and the next arrow brings it back into view. F7 or
Escape turns caret mode off, leaving the window open. The caret doesn't blink, so nothing runs
while it's on. A screen reader hears caret mode go on and off, and the line the caret is on as
it moves.

PDFs show their pages one under another, each drawn by poppler's `pdftoppm` as it scrolls into
view, and scroll like text. A locked or damaged PDF says so.

Expand Down
53 changes: 46 additions & 7 deletions crates/app/src/a11y.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub const PREVIEW_SHOWS: u64 = 53;
pub const PREVIEW_PREVIOUS: u64 = 54;
pub const PREVIEW_NEXT: u64 = 55;
pub const PREVIEW_CLOSE: u64 = 56;
/// The line of a document the caret is on, in caret mode.
pub const PREVIEW_CARET_LINE: u64 = 57;
// The Open With window. Its apps and headings are numbered from `OPEN_WITH_ROW0`, each keeping
// its number while the window is open.
pub const OPEN_WITH_SEARCH: u64 = 60;
Expand Down Expand Up @@ -127,6 +129,9 @@ pub enum Role {
Heading,
/// What the preview window shows.
Document,
/// A line of a document that can be read and selected from, not typed in: the caret's in
/// caret mode. Its text is the node's `field`.
Paragraph,
/// The file list, whose rows are table rows of cells.
Table,
ColumnHeader,
Expand Down Expand Up @@ -551,6 +556,8 @@ pub struct News {
pub name_refused: (u64, String),
/// How many times the folder showing has gone, and what was said the last time.
pub gone_said: (u64, String),
/// Whether the preview window's caret mode is on.
pub caret_mode: bool,
}

/// A job as the panel shows it.
Expand Down Expand Up @@ -598,6 +605,10 @@ impl Snapshot {
if is.gone_said.0 > was.gone_said.0 {
out.push((is.gone_said.1.clone(), false));
}
// Caret mode going on or off, whatever turned it: F7, Escape, or another file.
if is.caret_mode != was.caret_mode {
out.push((if is.caret_mode { "Caret mode on" } else { "Caret mode off" }.to_string(), false));
}
out
}
/// Whether a part is behind the menu or dialog that's open, so it can't be used. What's in
Expand Down Expand Up @@ -1004,9 +1015,13 @@ impl Link {
/// The preview window: the file's name, its kind and what's shown of it, and buttons to
/// walk its folder and close it.
fn build_viewer(&mut self, app: &App) -> Snapshot {
let s = app.a11y_preview();
let mut s = app.a11y_preview();
let (caret, area) = (s.caret.take(), s.area);
// In caret mode the arrows and Escape move the caret and leave the mode, so they aren't
// the buttons' keys then.
let keys = |k: &'static str| if caret.is_some() { "" } else { k };
let r = Rect::new(0, 0, app.w, app.h);
let fixed = vec![
let mut fixed = vec![
Node::new(FRAME, Role::Frame, if s.name.is_empty() { "Preview".to_string() } else { format!("{} - Preview", s.name) }, r, 0).with_children(vec![PREVIEW, PREVIEW_PREVIOUS, PREVIEW_NEXT, PREVIEW_CLOSE]),
// What has the keyboard, so moving to another file reads out its name, and the rest
// is there to be read.
Expand All @@ -1015,11 +1030,24 @@ impl Link {
Node::new(PREVIEW_KIND, Role::Label, s.kind, s.area, PREVIEW),
Node::new(PREVIEW_SHOWS, Role::Label, s.shows, s.foot, PREVIEW),
// Placed as the keys that do the same: there are no buttons on screen.
Node::new(PREVIEW_PREVIOUS, Role::PushButton, "Previous file", Rect::default(), FRAME).enabled(s.can_step.0).doing(click("Show the previous file in the folder", "Left")),
Node::new(PREVIEW_NEXT, Role::PushButton, "Next file", Rect::default(), FRAME).enabled(s.can_step.1).doing(click("Show the next file in the folder", "Right")),
Node::new(PREVIEW_CLOSE, Role::PushButton, "Close", Rect::default(), FRAME).doing(click("Close the preview", "Escape")),
Node::new(PREVIEW_PREVIOUS, Role::PushButton, "Previous file", Rect::default(), FRAME).enabled(s.can_step.0).doing(click("Show the previous file in the folder", keys("Left"))),
Node::new(PREVIEW_NEXT, Role::PushButton, "Next file", Rect::default(), FRAME).enabled(s.can_step.1).doing(click("Show the next file in the folder", keys("Right"))),
Node::new(PREVIEW_CLOSE, Role::PushButton, "Close", Rect::default(), FRAME).doing(click("Close the preview", keys("Escape"))),
];
Snapshot { fixed, rows: self.no_rows(), focus: Focus::Node(PREVIEW), window_focused: app.has_keyboard, dir: self.dir.clone(), text_geometry: Vec::new(), edit_gen: 0, news: News::default(), modal: None }
// In caret mode the keyboard is on the caret's line, which a screen reader reads as the
// caret moves. Each line is a new one, not an edit of the last (`edit_gen`): its caret is
// said to move, and the line is read from there.
let (mut focus, mut edit_gen) = (Focus::Node(PREVIEW), 0);
if let Some(c) = caret {
fixed[1].children.push(PREVIEW_CARET_LINE);
let mut n = Node::new(PREVIEW_CARET_LINE, Role::Paragraph, "", c.rect.intersect(area), PREVIEW);
n.field = Some(c.field);
fixed.push(n);
focus = Focus::Node(PREVIEW_CARET_LINE);
edit_gen = c.line.wrapping_add(1);
}
let news = News { caret_mode: focus != Focus::Node(PREVIEW), ..News::default() };
Snapshot { fixed, rows: self.no_rows(), focus, window_focused: app.has_keyboard, dir: self.dir.clone(), text_geometry: Vec::new(), edit_gen, news, modal: None }
}
}

Expand All @@ -1035,6 +1063,17 @@ pub struct PreviewText {
pub foot: Rect,
/// Whether there's a file before it and after it.
pub can_step: (bool, bool),
/// In caret mode, the line the caret is on.
pub caret: Option<CaretLine>,
}

/// The line of a document the caret is on, its caret and selection, as a field has them.
pub struct CaretLine {
pub field: Field,
/// Which line of which layout it is, so moving to another, or the same laid out again, is a
/// new line, not an edit.
pub line: u64,
pub rect: Rect,
}

/// The menu open, if one is: its parts, the menu first, and the part with the keyboard. That's
Expand Down Expand Up @@ -1350,7 +1389,7 @@ fn panel(app: &App, l: &Layout) -> (Node, Vec<Node>, News) {
parts.push(Node::new(DISMISS0 + i as u64, Role::PushButton, "Dismiss", close(first + i), NOTICES).described(text.clone()).showing(shown).doing(click("Dismiss the notice", "")));
}
let panel = Node::new(NOTICES, Role::Panel, "Notices", l.notices, FRAME).showing(l.notices.h > 0).with_children(parts.iter().map(|n| n.id).collect());
let news = News { posted: app.notices_posted, notices: app.notices.clone(), info: app.info_notices.clone(), jobs, ended: app.jobs_ended.clone(), name_refused: app.name_refused.clone(), gone_said: app.gone_said.clone() };
let news = News { posted: app.notices_posted, notices: app.notices.clone(), info: app.info_notices.clone(), jobs, ended: app.jobs_ended.clone(), name_refused: app.name_refused.clone(), gone_said: app.gone_said.clone(), caret_mode: false };
(panel, parts, news)
}

Expand Down
24 changes: 22 additions & 2 deletions crates/app/src/a11y_atspi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ fn role_of(r: Role) -> (u32, &'static str) {
Role::Label => (29, "label"),
Role::Heading => (83, "heading"),
Role::Document => (82, "document frame"),
Role::Paragraph => (73, "paragraph"),
Role::Table => (55, "table"),
Role::ColumnHeader => (10, "column header"),
Role::Link => (88, "link"),
Expand Down Expand Up @@ -479,6 +480,14 @@ impl Ctx {
_ => {}
}
}
// A document's line in caret mode is only read: the keys move its caret and select, and
// Ctrl+C copies. A screen reader asking to move them, or to edit it, is told no.
if let Target::Fixed(n) = &target
&& n.role == Role::Paragraph
&& (request || iface == EDITABLE_TEXT)
{
return self.reply(&h, &(false,));
}
match (iface, member.as_str()) {
(PROPS, "Get") => {
let Ok((i, name)) = body.deserialize::<(String, String)>() else { return self.error(&h, "org.freedesktop.DBus.Error.InvalidArgs", "") };
Expand Down Expand Up @@ -606,6 +615,7 @@ impl Ctx {
Role::PasswordText => on.extend([STATE_FOCUSABLE, STATE_EDITABLE, STATE_SINGLE_LINE]),
Role::MenuItem => on.extend([STATE_SELECTABLE, STATE_FOCUSABLE]),
Role::Document => on.extend([STATE_FOCUSABLE, STATE_READ_ONLY]),
Role::Paragraph => on.extend([STATE_FOCUSABLE, STATE_READ_ONLY, STATE_SINGLE_LINE, STATE_SELECTABLE_TEXT]),
Role::Table => on.extend([STATE_FOCUSABLE, STATE_MULTISELECTABLE, STATE_MANAGES_DESCENDANTS]),
Role::ProgressBar if snap.news.jobs.iter().any(|j| a11y::JOB0 + j.id == n.id && j.percent.is_none()) => on.push(STATE_INDETERMINATE),
Role::List => on.push(STATE_FOCUSABLE),
Expand Down Expand Up @@ -772,8 +782,11 @@ impl Ctx {
Target::Fixed(n) if n.role == Role::ProgressBar => v.push(VALUE),
_ => {}
}
if matches!(target, Target::Fixed(n) if n.field.is_some()) {
v.extend([TEXT, EDITABLE_TEXT]);
match target {
// A document's line is read, not typed in.
Target::Fixed(n) if n.field.is_some() && n.role == Role::Paragraph => v.push(TEXT),
Target::Fixed(n) if n.field.is_some() => v.extend([TEXT, EDITABLE_TEXT]),
_ => {}
}
self.reply(h, &(v,))
}
Expand Down Expand Up @@ -1326,6 +1339,13 @@ impl Ctx {
// new field under the same id, not an edit of the last.
if old.edit_gen == new.edit_gen {
self.emit_text_changes(&path, of, nf);
} else if n.role == Role::Paragraph {
// The caret went to another line of a document: its text isn't an edit, so
// only the caret is said to move, and a screen reader reads the line there.
self.event(&path, OBJECT_EVENT, "TextCaretMoved", ("", nf.chars_before(nf.caret) as i32), Variant::from(0i32));
if of.has_selection() || nf.has_selection() {
self.event(&path, OBJECT_EVENT, "TextSelectionChanged", ("", 0), Variant::from(0i32));
}
}
}
// Whether it can be used: a menu or dialog opening over it, or closing, changes that.
Expand Down
Loading
Loading