Skip to content

Commit

Permalink
Add text granularity setting to screen reader
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Nov 27, 2022
1 parent e01bad0 commit bf094b4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
publish = false

[dependencies]
atspi = { version = "^0.3.5", default-features = false, features = ["tokio"] }
atspi = { version = "^0.3.6", default-features = false, features = ["tokio"] }
bitflags = "1.3.2"
serde = "1.0.147"
smartstring = "1.0.1"
Expand Down
6 changes: 5 additions & 1 deletion common/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use serde::{
Deserialize,
};

use atspi::accessible::Role;
use atspi::{
accessible::Role,
text::TextGranularity,
};
use crate::modes::ScreenReaderMode;

#[derive(Eq, PartialEq, Clone, Hash, Serialize, Deserialize)]
Expand All @@ -28,5 +31,6 @@ pub enum ScreenReaderEvent {
Enable(Feature),
Disable(Feature),
ChangeMode(ScreenReaderMode),
ChangeGranularity(TextGranularity),
StructuralNavigation(Direction, Role),
}
5 changes: 5 additions & 0 deletions odilia/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ pub async fn sr_event(
}
},
Some(ScreenReaderEvent::StopSpeech) => tracing::trace!("Stopping speech!"),
Some(ScreenReaderEvent::ChangeGranularity(granularity)) => {
tracing::debug!("Changing granularity of read text.");
let mut sr_granularity = state.granularity.lock().await;
*sr_granularity = granularity;
},
Some(ScreenReaderEvent::ChangeMode(ScreenReaderMode { name })) => {
tracing::debug!("Changing mode to {:?}", name);
//let _ = mode_channel.send(ScreenReaderMode { name }).await;
Expand Down
6 changes: 5 additions & 1 deletion odilia/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tokio::sync::Mutex;
use zbus::{fdo::DBusProxy, names::UniqueName, zvariant::ObjectPath};

use crate::cache::Cache;
use atspi::{accessible::AccessibleProxy, cache::CacheProxy, accessible_ext::AccessibleExt, convertable::Convertable};
use atspi::{accessible::AccessibleProxy, cache::CacheProxy, accessible_ext::AccessibleExt, convertable::Convertable, text::TextGranularity};
use odilia_common::{modes::ScreenReaderMode, settings::ApplicationConfig, types::{TextSelectionArea }};

pub struct ScreenReaderState {
Expand All @@ -17,6 +17,7 @@ pub struct ScreenReaderState {
pub config: ApplicationConfig,
pub previous_caret_position: Cell<i32>,
pub mode: Mutex<ScreenReaderMode>,
pub granularity: Mutex<TextGranularity>,
pub accessible_history: Mutex<CircularQueue<(UniqueName<'static>, ObjectPath<'static>)>>,
pub cache: Cache,
}
Expand Down Expand Up @@ -67,13 +68,16 @@ impl ScreenReaderState {
let previous_caret_position = Cell::new(0);
let accessible_history = Mutex::new(CircularQueue::with_capacity(16));
let cache = Cache::new();

let granularity = Mutex::new(TextGranularity::Line);
Ok(Self {
atspi,
dbus,
speaker,
config,
previous_caret_position,
mode,
granularity,
accessible_history,
cache,
})
Expand Down
15 changes: 15 additions & 0 deletions sohkd/sohkdrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# using arrow keys will change the granulairty of your text reading.
~up
@odilia {"event":"changeGranularity","args":{"granularity":"line"}}
~down
@odilia {"event":"changeGranularity","args":{"granularity":"line"}}
~control + right
@odilia {"event":"changeGranularity","args":{"granularity":"word"}}
~control + left
@odilia {"event":"changeGranularity","args":{"granularity":"word"}}
~left
@odilia {"event":"changeGranularity","args":{"granularity":"char"}}
~right
@odilia {"event":"changeGranularity","args":{"granularity":"char"}}
# end of arrow keys

capslock + b
@enter browse
@odilia {"event":"changeMode","args":{"name":"browse"}}
Expand Down

0 comments on commit bf094b4

Please sign in to comment.