pipewire compatibility: Strip 0x from properties before parsing them

This commit is contained in:
2023-05-07 20:31:59 +02:00
parent 6dfd77c9e0
commit 822bd24f04

View File

@@ -1,6 +1,8 @@
use hidapi::{HidApi, HidDevice, HidError};
use libpulse_binding::proplist::Proplist;
use pulsectl::controllers::{types::DeviceInfo, DeviceControl, SinkController, SourceController, AppControl};
use pulsectl::controllers::{
types::DeviceInfo, AppControl, DeviceControl, SinkController, SourceController,
};
trait Headset {
const VENDOR_ID: u16;
@@ -26,8 +28,10 @@ fn find_device() -> Result<Option<HidDevice>, HidError> {
}
fn hex_prop_is(proplist: &Proplist, prop_name: &str, expected: u16) -> bool {
println!("{}", proplist.get_str(prop_name).unwrap());
proplist
.get_str(prop_name)
.map(|prop| prop.trim_start_matches("0x").to_owned())
.map(|prop| u16::from_str_radix(&prop, 16).unwrap())
.map(|prop| prop == expected)
.unwrap_or(false)
@@ -48,10 +52,14 @@ fn switch_sink(new_sink: &DeviceInfo, sink_controller: &mut SinkController) {
let old_sink = sink_controller.get_default_device().unwrap();
for app in sink_controller.list_applications().unwrap() {
if app.connection_id == old_sink.index {
sink_controller.move_app_by_index(app.index, new_sink.index).unwrap();
sink_controller
.move_app_by_index(app.index, new_sink.index)
.unwrap();
}
}
sink_controller.set_default_device(new_sink.name.as_ref().unwrap()).unwrap();
sink_controller
.set_default_device(new_sink.name.as_ref().unwrap())
.unwrap();
}
fn handle_report(device: &HidDevice, report: &[u8]) -> Result<(), HidError> {