diff --git a/crates/openlogi-core/src/device.rs b/crates/openlogi-core/src/device.rs index d78dfed4f4..9fb6b1a1cb 100644 --- a/crates/openlogi-core/src/device.rs +++ b/crates/openlogi-core/src/device.rs @@ -154,7 +154,8 @@ pub struct Capabilities { pub hires_wheel: bool, /// A horizontal thumb wheel is available: either the dedicated HID++ /// `0x2150 Thumbwheel` feature or a legacy `0x6501 Gestures2` descriptor - /// (gesture id 46, used by MX Master 2S). + /// (gesture id 46, used by MX Master 2S) that firmware lets software + /// divert. #[serde(default)] pub thumbwheel: bool, /// Programmable haptic feedback — reverse-engineered HID++ `0x19b0`. diff --git a/crates/openlogi-device/src/inventory/features.rs b/crates/openlogi-device/src/inventory/features.rs index 60610bd554..355e851e14 100644 --- a/crates/openlogi-device/src/inventory/features.rs +++ b/crates/openlogi-device/src/inventory/features.rs @@ -748,11 +748,16 @@ async fn probe_extra_capabilities( // Older MX mice (notably MX Master 2S) expose the horizontal wheel as // Gestures2 gesture id 46 instead of the newer dedicated 0x2150 // Thumbwheel feature. Inspect the descriptor table so a generic 0x6501 - // touch device does not become a false-positive thumbwheel device. + // touch device does not become a false-positive thumbwheel device. Every + // thumb wheel setting needs the wheel diverted, so a gesture 46 the + // firmware does not let software divert is no thumb wheel to OpenLogi. if !caps.thumbwheel && let Some(feature) = device.get_feature::() { - caps.thumbwheel = feature.has_thumbwheel().await.unwrap_or(false); + caps.thumbwheel = feature + .thumbwheel() + .await + .is_ok_and(|gesture| gesture.is_some_and(|g| g.diversion_index.is_some())); } // Logi Options+ writes a keyboard's platform only when `0x4531` lets // software set it, so a keyboard that does not is offered no setting. @@ -844,6 +849,7 @@ fn force_sensing_error_answer(error: Hidpp20Error) -> Result { mod tests { use std::time::Duration; + use hidpp::feature::gestures2::THUMBWHEEL_GESTURE_ID; use hidpp::feature::{ CreatableFeature as _, FeatureType, adc_measurement::AdcMeasurementFeature, battery_status::BatteryStatusFeature, battery_voltage::BatteryVoltageFeature, @@ -1164,6 +1170,36 @@ mod tests { } } + #[tokio::test] + async fn gestures2_thumb_wheel_counts_only_when_it_can_be_diverted() { + // MX Master (b01e) lists gesture 46 without the divertable bit (0x02). + for (flags, supported) in [(0x83_u8, true), (0x81, false)] { + let (raw, _) = ScriptedRawHidChannel::with_dynamic_responder(move |request| { + let mut response = vec![0; 20]; + response[..4].copy_from_slice(&request[..4]); + response[0] = 0x11; + let features = [0x0001_u16, 0x6501]; + match (request[2], request[3] >> 4) { + (0, 1) => response[4] = 4, + (0, 0) => response[4] = 1, + (1, 0) => response[4] = 2, + (1, 1) => response[4..6] + .copy_from_slice(&features[usize::from(request[4]) - 1].to_be_bytes()), + (2, 0) => { + response[4..6].copy_from_slice(&[flags, THUMBWHEEL_GESTURE_ID]); + response[6] = 0x01; + } + _ => panic!("unexpected capability request: {request:02x?}"), + } + Some(response) + }); + let channel = scripted_channel(raw).await; + let probe = probe_features(&channel, 0xff, None, None).await.0; + let caps = probe.capabilities().unwrap(); + assert_eq!(caps.thumbwheel, supported, "flags {flags:02x}"); + } + } + /// Probe a keyboard whose `0x4531` (at index 2) reports the capability /// word `capabilities`, or fails the read when it is `None`. async fn multi_platform_probe(capabilities: Option) -> ProbedFeatures { diff --git a/crates/openlogi-device/src/inventory/persist.rs b/crates/openlogi-device/src/inventory/persist.rs index 8130406690..7d365b87aa 100644 --- a/crates/openlogi-device/src/inventory/persist.rs +++ b/crates/openlogi-device/src/inventory/persist.rs @@ -60,7 +60,9 @@ use super::features::{BatteryProbe, ProbedFeatures}; /// which also records HID++ 1.0, and adds the HID++ 1.0 battery registers to /// `BatteryProbe`. /// v20 adds the `Capabilities::change_host` flag (`0x1814` host switching). -const SCHEMA_VERSION: u32 = 20; +/// v21 sets `Capabilities::thumbwheel` for a Gestures2 thumb wheel only when +/// firmware lets software divert it. +const SCHEMA_VERSION: u32 = 21; impl ProbeCacheError { /// Report why a store could not keep a snapshot. diff --git a/crates/openlogi-device/src/session/gesture/arm.rs b/crates/openlogi-device/src/session/gesture/arm.rs index c3cc951951..943e2b2568 100644 --- a/crates/openlogi-device/src/session/gesture/arm.rs +++ b/crates/openlogi-device/src/session/gesture/arm.rs @@ -399,7 +399,10 @@ async fn arm_gesture_thumbwheel( let feature = Gestures2Feature::new(Arc::clone(chan), slot, info.index); match feature.thumbwheel_diverted().await { Ok(Some(_)) => {} - Ok(None) => return Ok(()), + Ok(None) => { + warn!("gesture thumb wheel is absent or not divertable — left native"); + return Ok(()); + } Err(error @ Hidpp20Error::Channel(_)) => return Err(error.into()), Err(error) => { warn!( diff --git a/crates/openlogi-hidpp/src/feature/gestures2.rs b/crates/openlogi-hidpp/src/feature/gestures2.rs index 697d8c40fb..878ee9f115 100644 --- a/crates/openlogi-hidpp/src/feature/gestures2.rs +++ b/crates/openlogi-hidpp/src/feature/gestures2.rs @@ -99,11 +99,6 @@ impl Gestures2Feature { Err(Hidpp20Error::UnsupportedResponse) } - /// Return whether this device's descriptor table contains gesture id 46. - pub async fn has_thumbwheel(&self) -> Result { - Ok(self.thumbwheel().await?.is_some()) - } - /// Read the current diversion state for gesture id 46. `None` means the /// thumb wheel is absent or present but not divertable. pub async fn thumbwheel_diverted(&self) -> Result, Hidpp20Error> { diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 5c8602f951..813a0803f3 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -207,6 +207,11 @@ Common device fields are: direction only; the other direction keeps inheriting the default profile. Actions that last as long as a press (**DPI Shift**, **G-Shift**, a held shortcut) are not offered there, because a wheel turn has no release. + On mice without the `0x2150` thumb wheel feature, such as the MX Master and + MX Master 2S, the wheel is HID++ `0x6501` gesture 46, and its bindings work + only when the mouse's firmware lets software divert that gesture. When it + does not, the desktop shows no thumb wheel settings for the mouse and the + wheel keeps scrolling horizontally. Keyboard keys are named by their HID++ `0x1b04` control: a catalog name such as `KeyScreenCapture`, `KeyCalculator` or `KeyLock`, or `control:0x` for any control `openlogi diag controls` reports as divertable. A bound key is