mirror of
https://gitlab.steamos.cloud/holo/steamos-manager.git
synced 2025-07-15 10:46:41 -04:00
WIP: Add accessibility1 interface for setting/getting mono feature.
This commit is contained in:
parent
4fa8fe6900
commit
84d0532d8b
4 changed files with 176 additions and 1 deletions
|
@ -11,6 +11,22 @@
|
|||
-->
|
||||
|
||||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
||||
<!--
|
||||
com.steampowered.SteamOSManager1.Accessibility1
|
||||
@short_description: Optional interface to manipulate accessibility
|
||||
features.
|
||||
-->
|
||||
<interface name="com.steampowered.SteamOSManager1.Accessibility1">
|
||||
|
||||
<!--
|
||||
AudioMode:
|
||||
|
||||
The audio mode. Either 'mono' or 'stereo'.
|
||||
-->
|
||||
<property name="AudioMode" type="s" access="readwrite"/>
|
||||
|
||||
</interface>
|
||||
|
||||
<!--
|
||||
com.steampowered.SteamOSManager1.AmbientLightSensor1
|
||||
@short_description: Optional interface to interact with the built-in
|
||||
|
|
115
steamos-manager/src/accessibility.rs
Normal file
115
steamos-manager/src/accessibility.rs
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright © 2025 Collabora Ltd.
|
||||
* Copyright © 2025 Valve Software
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::Result;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use strum::{Display, EnumString};
|
||||
use tracing::warn;
|
||||
|
||||
#[cfg(not(test))]
|
||||
use crate::process::script_output;
|
||||
|
||||
#[derive(Display, EnumString, PartialEq, Debug, Copy, Clone, TryFromPrimitive)]
|
||||
#[strum(serialize_all = "snake_case", ascii_case_insensitive)]
|
||||
#[repr(u32)]
|
||||
pub enum AudioMode {
|
||||
Mono = 0,
|
||||
Stereo = 1,
|
||||
}
|
||||
|
||||
pub(crate) struct AccessibilityManager {
|
||||
audio_mode: Option<AudioMode>,
|
||||
}
|
||||
|
||||
impl AccessibilityManager {
|
||||
pub async fn new() -> Result<AccessibilityManager> {
|
||||
let mut manager = AccessibilityManager { audio_mode: None };
|
||||
let _ = manager
|
||||
.load_values()
|
||||
.await
|
||||
.inspect_err(|e| warn!("Failed to load accessibility configuration: {e}"));
|
||||
Ok(manager)
|
||||
}
|
||||
|
||||
pub fn audio_mode(&self) -> Option<AudioMode> {
|
||||
self.audio_mode
|
||||
}
|
||||
|
||||
pub async fn set_audio_mode(&mut self, mode: AudioMode) -> Result<()> {
|
||||
if self.audio_mode == Some(mode) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
match mode {
|
||||
AudioMode::Mono => {
|
||||
let _output = script_output(
|
||||
"/usr/bin/wpctl",
|
||||
&["settings", "node.features.audio.mono", "true"],
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
AudioMode::Stereo => {
|
||||
let _output = script_output(
|
||||
"/usr/bin/wpctl",
|
||||
&["settings", "node.features.audio.mono", "false"],
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
self.audio_mode = Some(mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
async fn load_values(&mut self) -> Result<()> {
|
||||
let output =
|
||||
script_output("/usr/bin/wpctl", &["settings", "node.features.audio.mono"]).await?;
|
||||
|
||||
match output.trim() {
|
||||
"true" => {
|
||||
self.audio_mode = Some(AudioMode::Mono);
|
||||
}
|
||||
"false" => {
|
||||
self.audio_mode = Some(AudioMode::Stereo);
|
||||
}
|
||||
_ => {
|
||||
warn!("Unable to get audio mode from wpctl output");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
async fn load_values(&mut self) -> Result<()> {
|
||||
// Just start in stereo mode in tests.
|
||||
self.audio_mode = Some(AudioMode::Stereo);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_set_mode() {
|
||||
let mut manager = AccessibilityManager::new()
|
||||
.await
|
||||
.expect("AccessibilityManager::new");
|
||||
manager.audio_mode = Some(AudioMode::Mono);
|
||||
manager.set_audio_mode(AudioMode::Stereo).await.unwrap();
|
||||
assert_eq!(manager.audio_mode, Some(AudioMode::Stereo));
|
||||
assert_eq!(manager.audio_mode(), Some(AudioMode::Stereo));
|
||||
|
||||
manager.set_audio_mode(AudioMode::Mono).await.unwrap();
|
||||
assert_eq!(manager.audio_mode, Some(AudioMode::Mono));
|
||||
assert_eq!(manager.audio_mode(), Some(AudioMode::Mono));
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ mod systemd;
|
|||
mod udev;
|
||||
mod uinput;
|
||||
|
||||
pub mod accessibility;
|
||||
pub mod cec;
|
||||
pub mod daemon;
|
||||
pub mod hardware;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
use anyhow::{Error, Result};
|
||||
use anyhow::{anyhow, Error, Result};
|
||||
use std::collections::HashMap;
|
||||
use tokio::fs::try_exists;
|
||||
use tokio::sync::mpsc::{Sender, UnboundedSender};
|
||||
|
@ -18,6 +18,7 @@ use zbus::proxy::{Builder, CacheProperties};
|
|||
use zbus::zvariant::Fd;
|
||||
use zbus::{fdo, interface, zvariant, Connection, ObjectServer, Proxy};
|
||||
|
||||
use crate::accessibility::{AccessibilityManager, AudioMode};
|
||||
use crate::cec::{HdmiCecControl, HdmiCecState};
|
||||
use crate::daemon::user::Command;
|
||||
use crate::daemon::DaemonCommand;
|
||||
|
@ -107,6 +108,10 @@ struct SteamOSManager {
|
|||
_job_manager: UnboundedSender<JobManagerCommand>,
|
||||
}
|
||||
|
||||
struct AccessibilityManager1 {
|
||||
manager: AccessibilityManager,
|
||||
}
|
||||
|
||||
struct AmbientLightSensor1 {
|
||||
proxy: Proxy<'static>,
|
||||
}
|
||||
|
@ -258,6 +263,37 @@ impl SteamOSManager {
|
|||
}
|
||||
}
|
||||
|
||||
impl AccessibilityManager1 {
|
||||
async fn new() -> Result<AccessibilityManager1> {
|
||||
let manager = AccessibilityManager::new().await?;
|
||||
Ok(AccessibilityManager1 { manager })
|
||||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.Accessiility1")]
|
||||
impl AccessibilityManager1 {
|
||||
#[zbus(property)]
|
||||
async fn audio_mode(&self) -> fdo::Result<String> {
|
||||
let mode = self.manager.audio_mode();
|
||||
match mode {
|
||||
Some(mode) => Ok(mode.to_string()),
|
||||
_ => Err(to_zbus_fdo_error(anyhow!("Unknown audio mode"))),
|
||||
}
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
async fn set_audio_mode(&mut self, m: &str) -> fdo::Result<()> {
|
||||
let mode = match AudioMode::try_from(m) {
|
||||
Ok(mode) => mode,
|
||||
Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string())),
|
||||
};
|
||||
self.manager
|
||||
.set_audio_mode(mode)
|
||||
.await
|
||||
.map_err(to_zbus_fdo_error)
|
||||
}
|
||||
}
|
||||
|
||||
#[interface(name = "com.steampowered.SteamOSManager1.AmbientLightSensor1")]
|
||||
impl AmbientLightSensor1 {
|
||||
#[zbus(property(emits_changed_signal = "false"))]
|
||||
|
@ -1090,6 +1126,7 @@ pub(crate) async fn create_interfaces(
|
|||
|
||||
let manager = SteamOSManager::new(system.clone(), proxy.clone(), job_manager.clone()).await?;
|
||||
|
||||
let accessibility_manager = AccessibilityManager1::new().await?;
|
||||
let als = AmbientLightSensor1 {
|
||||
proxy: proxy.clone(),
|
||||
};
|
||||
|
@ -1165,6 +1202,12 @@ pub(crate) async fn create_interfaces(
|
|||
|
||||
object_server.at(MANAGER_PATH, manager2).await?;
|
||||
|
||||
if try_exists(path("/usr/bin/wpctl")).await? {
|
||||
object_server
|
||||
.at(MANAGER_PATH, accessibility_manager)
|
||||
.await?;
|
||||
}
|
||||
|
||||
if try_exists(path("/usr/bin/orca")).await? {
|
||||
object_server.at(MANAGER_PATH, screen_reader).await?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue