fix(sound): Bluez5 device support

This commit is contained in:
Michael Aaron Murphy 2024-08-14 01:16:06 +02:00
parent 5e054b1c3c
commit 6f26ad7974
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 28 additions and 16 deletions

14
Cargo.lock generated
View file

@ -1621,7 +1621,7 @@ dependencies = [
[[package]]
name = "cosmic-settings-subscriptions"
version = "0.1.0"
source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#10d168ccdee6b6746c5ada4a6804833c021b40d8"
source = "git+https://github.com/pop-os/cosmic-settings-subscriptions#9634f708d079f4b6336e02ed3e22ede6ee7f7cdb"
dependencies = [
"futures",
"iced_futures",
@ -1805,7 +1805,7 @@ version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=20fda69#20fda698341efbdc870b8027d6d49f5bf3f36109"
dependencies = [
"bitflags 2.6.0",
"libloading 0.8.5",
"libloading 0.7.4",
"winapi",
]
@ -1960,7 +1960,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412"
dependencies = [
"libloading 0.8.5",
"libloading 0.7.4",
]
[[package]]
@ -2829,7 +2829,7 @@ dependencies = [
"bitflags 2.6.0",
"com",
"libc",
"libloading 0.8.5",
"libloading 0.7.4",
"thiserror",
"widestring",
"winapi",
@ -3000,7 +3000,7 @@ dependencies = [
[[package]]
name = "iced_accessibility"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic#4dd0f72f155b8705a30c2d42282f0bf1e5159e10"
source = "git+https://github.com/pop-os/libcosmic#c9f8f485373e02ef849c83d3bbdf0fdd2bf4a24c"
dependencies = [
"accesskit",
"accesskit_unix",
@ -3009,7 +3009,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.12.0"
source = "git+https://github.com/pop-os/libcosmic#4dd0f72f155b8705a30c2d42282f0bf1e5159e10"
source = "git+https://github.com/pop-os/libcosmic#c9f8f485373e02ef849c83d3bbdf0fdd2bf4a24c"
dependencies = [
"bitflags 2.6.0",
"dnd",
@ -7449,7 +7449,7 @@ dependencies = [
"js-sys",
"khronos-egl",
"libc",
"libloading 0.8.5",
"libloading 0.7.4",
"log",
"metal",
"naga",

View file

@ -37,7 +37,6 @@ pub enum Message {
SourceMuteToggle,
}
pub type CardId = u32;
pub type NodeId = u32;
pub type ProfileId = u32;
@ -52,11 +51,17 @@ struct Profile {
identifier: String,
}
#[derive(Clone, Eq, Hash, PartialEq)]
enum DeviceId {
Alsa(u32),
Bluez5(String),
}
#[derive(Default)]
pub struct Page {
pipewire_thread: Option<(tokio::sync::oneshot::Sender<()>, pipewire::Sender<()>)>,
pulse_thread: Option<tokio::sync::oneshot::Sender<()>>,
alsa_cards: HashMap<CardId, Card>,
devices: HashMap<DeviceId, Card>,
default_sink: String,
default_source: String,
@ -179,7 +184,7 @@ impl page::AutoBind<crate::pages::Message> for Page {}
impl Page {
fn set_default_sink(&mut self) {
for card in self.alsa_cards.values() {
for card in self.devices.values() {
if let pipewire::MediaClass::Sink = card.class {
for (&node_id, profile) in &card.profiles {
if profile.identifier == self.default_sink {
@ -192,7 +197,7 @@ impl Page {
}
fn set_default_source(&mut self) {
for card in self.alsa_cards.values() {
for card in self.devices.values() {
if let pipewire::MediaClass::Source = card.class {
for (&node_id, profile) in &card.profiles {
if profile.identifier == self.default_source {
@ -304,8 +309,15 @@ impl Page {
}
let card = self
.alsa_cards
.entry(device.alsa_card)
.devices
.entry(match device.variant {
pipewire::DeviceVariant::Alsa { alsa_card, .. } => {
DeviceId::Alsa(alsa_card)
}
pipewire::DeviceVariant::Bluez5 { address, .. } => {
DeviceId::Bluez5(address)
}
})
.or_insert_with(|| Card {
class: device.media_class,
// name: device.alsa_card_name,
@ -323,17 +335,17 @@ impl Page {
Message::Pipewire(pipewire::DeviceEvent::Remove(device_id)) => {
let mut remove = None;
for (card_id, card) in &mut self.alsa_cards {
for (card_id, card) in &mut self.devices {
if card.profiles.remove(&device_id).is_some() {
if card.profiles.is_empty() {
remove = Some(*card_id);
remove = Some(card_id.clone());
}
break;
}
}
if let Some(card_id) = remove {
_ = self.alsa_cards.remove(&card_id);
_ = self.devices.remove(&card_id);
}
if let Some(pos) = self.sink_ids.iter().position(|&id| id == device_id) {