Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/openlogi-core/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
40 changes: 38 additions & 2 deletions crates/openlogi-device/src/inventory/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Gestures2Feature>()
{
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.
Expand Down Expand Up @@ -844,6 +849,7 @@ fn force_sensing_error_answer(error: Hidpp20Error) -> Result<bool, ()> {
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,
Expand Down Expand Up @@ -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}");
Comment on lines +1196 to +1199

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Probe test checks too little

Blocking. The new test awaits scripted_channel and probe_features without a test deadline, then checks only caps.thumbwheel. This violates the repository requirement that async tests time out with a clear failure message and assert the whole reading. A stalled probe lacks a clear test-level failure, while changes to other capabilities or completeness can pass unnoticed.

Wrap setup and probing in a timeout, then compare the expected capabilities and completeness for both flag values. The test code establishes these gaps; no runtime hang was reproduced.

Rule Used: Severity: medium. Every bug fix ships a regression test that fails without the fix, and the PR states the counter-proof (the reverted line or the killed mutant). A test that passes with the fix reverted is not a regression test: ask for inputs where ... (source)

}
}

/// 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<u16>) -> ProbedFeatures {
Expand Down
4 changes: 3 additions & 1 deletion crates/openlogi-device/src/inventory/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion crates/openlogi-device/src/session/gesture/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
5 changes: 0 additions & 5 deletions crates/openlogi-hidpp/src/feature/gestures2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, Hidpp20Error> {
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<Option<bool>, Hidpp20Error> {
Expand Down
5 changes: 5 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<cid>` for
any control `openlogi diag controls` reports as divertable. A bound key is
Expand Down
Loading