pipewire compatibility: Strip 0x from properties before parsing them
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -1,6 +1,8 @@
|
|||||||
use hidapi::{HidApi, HidDevice, HidError};
|
use hidapi::{HidApi, HidDevice, HidError};
|
||||||
use libpulse_binding::proplist::Proplist;
|
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 {
|
trait Headset {
|
||||||
const VENDOR_ID: u16;
|
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 {
|
fn hex_prop_is(proplist: &Proplist, prop_name: &str, expected: u16) -> bool {
|
||||||
|
println!("{}", proplist.get_str(prop_name).unwrap());
|
||||||
proplist
|
proplist
|
||||||
.get_str(prop_name)
|
.get_str(prop_name)
|
||||||
|
.map(|prop| prop.trim_start_matches("0x").to_owned())
|
||||||
.map(|prop| u16::from_str_radix(&prop, 16).unwrap())
|
.map(|prop| u16::from_str_radix(&prop, 16).unwrap())
|
||||||
.map(|prop| prop == expected)
|
.map(|prop| prop == expected)
|
||||||
.unwrap_or(false)
|
.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();
|
let old_sink = sink_controller.get_default_device().unwrap();
|
||||||
for app in sink_controller.list_applications().unwrap() {
|
for app in sink_controller.list_applications().unwrap() {
|
||||||
if app.connection_id == old_sink.index {
|
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> {
|
fn handle_report(device: &HidDevice, report: &[u8]) -> Result<(), HidError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user