From 822bd24f0480c50ac9c00688c0d48463945d8766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Sun, 7 May 2023 20:31:59 +0200 Subject: [PATCH] pipewire compatibility: Strip 0x from properties before parsing them --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 37c6c61..960331c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, 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> {