From 2c3b69a621f4d636a48d397a3ae816da3f0b8524 Mon Sep 17 00:00:00 2001 From: Snekxs <26660858+snekxs@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:29:25 -0600 Subject: [PATCH 1/2] fix(discovery): list devices the registry does not claim by vendor id (#134) --- src/drivers/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 9146d50..299d196 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -150,20 +150,21 @@ fn discovered_brand(info: &hidapi::DeviceInfo) -> Option<&'static str> { /// Which devices are mice, and their brands, comes from the control panel's /// own driver registry (see `registry`). A device is opened only the first /// time it appears, to read its report descriptors, and only if it matches -/// the registry's filters. When the registry cannot be reached (no Node.js), -/// discovery falls back to Bridge's vendor-id table. +/// the registry's filters. Devices the registry does not claim, and every +/// device when it cannot be reached (no Node.js), come from Bridge's +/// vendor-id table. pub fn detect_mice() -> Vec { let Some(devices) = registry::devices() else { return detect_by_vendor(); }; let mut mice = mice_from_registry(devices); - // Pulsar has a Rust driver of its own, which reads models the registry - // may not list; those are still found by vendor id. + // Discovery is additive: a mouse the registry does not claim (or whose + // descriptors could not be read) is still listed by vendor id, so it + // never vanishes from Bridge. Its battery read just fails softly. for mouse in detect_by_vendor() { - if mouse.vendor_id == pulsar::VENDOR_ID - && !mice.iter().any(|known| { - known.vendor_id == mouse.vendor_id && known.product_id == mouse.product_id - }) + if !mice + .iter() + .any(|known| known.vendor_id == mouse.vendor_id && known.product_id == mouse.product_id) { mice.push(mouse); } From 54198073b52813a8e3adba2733b5e49a3e058d59 Mon Sep 17 00:00:00 2001 From: Snekxs <26660858+snekxs@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:36:19 -0600 Subject: [PATCH 2/2] fix(discovery): keep same-model mice with different serials apart (#134) --- src/drivers/mod.rs | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/drivers/mod.rs b/src/drivers/mod.rs index 299d196..dd2fb75 100644 --- a/src/drivers/mod.rs +++ b/src/drivers/mod.rs @@ -161,15 +161,26 @@ pub fn detect_mice() -> Vec { // Discovery is additive: a mouse the registry does not claim (or whose // descriptors could not be read) is still listed by vendor id, so it // never vanishes from Bridge. Its battery read just fails softly. - for mouse in detect_by_vendor() { + backfill(&mut mice, detect_by_vendor()); + mice +} + +/// Adds the vendor-found mice the registry did not list. The brand prefix of +/// a device id can differ between the two sources, so a physical mouse is +/// compared by the id tail (serial, else `vid:pid`): two mice of one model +/// with different serials stay two. +fn backfill(mice: &mut Vec, found: Vec) { + fn tail(id: &str) -> &str { + id.split_once(':').map_or(id, |(_, tail)| tail) + } + for mouse in found { if !mice .iter() - .any(|known| known.vendor_id == mouse.vendor_id && known.product_id == mouse.product_id) + .any(|known| tail(&known.device_id) == tail(&mouse.device_id)) { mice.push(mouse); } } - mice } fn mice_from_registry(devices: Vec<(crate::hid::DescribedDevice, String)>) -> Vec { @@ -458,6 +469,31 @@ mod tests { use crate::config::{ProfileApplication, ProfileDevice, ProfileSettings}; use crate::hid::DescribedDevice; + fn mouse(id: &str) -> DetectedMouse { + DetectedMouse { + device_id: id.into(), + name: "m".into(), + vendor_id: 1, + product_id: 2, + } + } + + #[test] + fn backfill_adds_unclaimed_mice_but_not_ones_already_listed() { + let mut mice = vec![mouse("Razer:AAA")]; + backfill( + &mut mice, + vec![ + mouse("Razer:AAA"), + mouse("Razer:BBB"), + mouse("Acme:0001:0002"), + ], + ); + let ids: Vec<_> = mice.iter().map(|m| m.device_id.as_str()).collect(); + // Same model, different serial: kept. Same serial: not repeated. + assert_eq!(ids, ["Razer:AAA", "Razer:BBB", "Acme:0001:0002"]); + } + #[test] fn registry_mice_keep_the_device_id_shape_and_merge_a_mouses_interfaces() { let mice = mice_from_registry(vec![