Fennec OS 0.3.3: clear names for the sound outputs
Settings → Sound listed ALSA's descriptions, "Built-in Audio Digital Stereo (HDMI)" and "Built-in Audio Stereo", which look alike; the second is the 3.5 mm jack, and picking it left the TV silent. They now read "TV · HDMI" (on the Raspberry Pi "TV · HDMI 1" / "TV · HDMI 2") and "Jack-kimenet (3,5 mm)", listed after the TV and Bluetooth outputs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -476,14 +476,46 @@ pub fn audio_outputs() -> Result<Vec<AudioOutput>> {
|
||||
for sink in sinks {
|
||||
let Some(name) = sink.get("name").and_then(|v| v.as_str()) else { continue };
|
||||
if name == "auto_null" { continue; }
|
||||
let label = sink.get("description").and_then(|v| v.as_str()).unwrap_or(name).to_string();
|
||||
let description = sink.get("description").and_then(|v| v.as_str()).unwrap_or(name);
|
||||
let label = output_label(name, description);
|
||||
let bluetooth = name.starts_with("bluez_output.");
|
||||
outputs.push(AudioOutput { name: name.into(), label, bluetooth, selected: name == default });
|
||||
}
|
||||
outputs.sort_by_key(|o| (!o.selected, o.bluetooth, o.label.to_lowercase()));
|
||||
// The selected one, then the TV, Bluetooth, anything else, the jack last.
|
||||
let rank = |o: &AudioOutput| match () {
|
||||
_ if o.label.starts_with("TV") => 0,
|
||||
_ if o.bluetooth => 1,
|
||||
_ if o.label.starts_with("Jack") => 3,
|
||||
_ => 2,
|
||||
};
|
||||
outputs.sort_by_key(|o| (!o.selected, rank(o), o.label.to_lowercase()));
|
||||
Ok(outputs)
|
||||
}
|
||||
|
||||
/// A name people recognise for a sound output. ALSA's descriptions
|
||||
/// ("Built-in Audio Digital Stereo (HDMI)", "Built-in Audio Stereo") look
|
||||
/// alike; the analog one is the 3.5 mm jack, not the TV.
|
||||
fn output_label(name: &str, description: &str) -> String {
|
||||
if name.starts_with("bluez_output.") {
|
||||
return description.to_string();
|
||||
}
|
||||
let n = name.to_ascii_lowercase();
|
||||
if n.contains("hdmi") {
|
||||
// Raspberry Pi 4: two HDMI ports (fef00700 = HDMI 0, fef05700 = HDMI 1).
|
||||
return match () {
|
||||
_ if n.contains("fef05700") => "TV · HDMI 2".into(),
|
||||
_ if n.contains("fef00700") => "TV · HDMI 1".into(),
|
||||
_ => "TV · HDMI".into(),
|
||||
};
|
||||
}
|
||||
if n.starts_with("alsa_output.")
|
||||
&& (n.contains("analog") || n.contains("stereo-fallback") || n.contains("headphones") || n.contains("mailbox"))
|
||||
{
|
||||
return "Jack-kimenet (3,5 mm)".into();
|
||||
}
|
||||
description.to_string()
|
||||
}
|
||||
|
||||
pub fn set_audio_output(name: &str) -> Result<()> {
|
||||
if demo() {
|
||||
*DEMO_AUDIO.lock().unwrap() = Some(name.into());
|
||||
@@ -1129,6 +1161,16 @@ pub fn confirm_shell_trial() {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn output_labels() {
|
||||
assert_eq!(output_label("alsa_output.platform-fef00700.hdmi.hdmi-stereo", "Built-in Audio Digital Stereo (HDMI)"), "TV · HDMI 1");
|
||||
assert_eq!(output_label("alsa_output.platform-fef05700.hdmi.hdmi-stereo", "Built-in Audio Digital Stereo (HDMI)"), "TV · HDMI 2");
|
||||
assert_eq!(output_label("alsa_output.pci-0000_00_1f.3.hdmi-stereo", "HDA Intel PCH HDMI"), "TV · HDMI");
|
||||
assert_eq!(output_label("alsa_output.platform-fe00b840.mailbox.stereo-fallback", "Built-in Audio Stereo"), "Jack-kimenet (3,5 mm)");
|
||||
assert_eq!(output_label("alsa_output.pci-0000_00_1f.3.analog-stereo", "Built-in Audio Analog Stereo"), "Jack-kimenet (3,5 mm)");
|
||||
assert_eq!(output_label("bluez_output.D8_37_3B_73_C9_45.1", "AirPods Pro"), "AirPods Pro");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_wlr_randr() {
|
||||
let text = "HDMI-A-1 \"Samsung Electric Company SAMSUNG (HDMI-A-1)\"\n Enabled: yes\n Modes:\n 3840x2160 px, 30.000000 Hz\n 1920x1080 px, 60.000000 Hz (preferred, current)\n 1920x1080 px, 59.940002 Hz\n 3840x2160 px, 60.000000 Hz\n 720x400 px, 70.082001 Hz\n Position: 0,0\n Transform: normal\n Scale: 1.000000\n";
|
||||
|
||||
Reference in New Issue
Block a user