Skip to content

Commit caed44f

Browse files
committed
Select among primary and secondary
1 parent 83f071d commit caed44f

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

anxious-scroll-daemon.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Unit]
22
Description=Anxious Scroll Daemon - Mouse scroll wheel acceleration
3-
Documentation=https://github.com/your-repo/cursor-anxious
3+
Documentation=https://github.com/Snehal-Reddy/cursor-anxious
44
After=multi-user.target
55
Wants=multi-user.target
66

src/main.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use evdev::{Device, EventType, RelativeAxisCode, uinput::VirtualDevice};
44
use log::{error, info};
55
use mouse_scroll_daemon::{AnxiousParams, AnxiousState, process_events};
66
use std::path::PathBuf;
7+
use std::path::Path;
78

89
#[derive(Parser, Debug)]
910
#[command(author, version, about, long_about = None)]
@@ -74,6 +75,7 @@ fn find_mouse_device(device_path: Option<PathBuf>) -> Result<Device> {
7475

7576
info!("Searching for mouse devices...");
7677
let devices = evdev::enumerate().collect::<Vec<_>>();
78+
let mut best: Option<(Device, u16, std::path::PathBuf)> = None;
7779

7880
for (path, device) in devices {
7981
let name = device.name().unwrap_or("Unknown");
@@ -87,13 +89,37 @@ fn find_mouse_device(device_path: Option<PathBuf>) -> Result<Device> {
8789
&& relative_axes.contains(RelativeAxisCode::REL_WHEEL)
8890
&& relative_axes.contains(RelativeAxisCode::REL_HWHEEL)
8991
{
90-
info!("Found mouse device: {} at {}", name, path.display());
91-
return Ok(device);
92+
let input_id = device.input_id();
93+
let product = input_id.product();
94+
info!(
95+
"Found mouse device: {} at {} (product: 0x{:04x})",
96+
name,
97+
path.display(),
98+
product
99+
);
100+
match &mut best {
101+
None => best = Some((device, product, path)),
102+
Some((_, best_prod, _)) => {
103+
if product < *best_prod {
104+
best = Some((device, product, path));
105+
}
106+
}
107+
}
92108
}
93109
}
94110
}
95111
}
96112

113+
if let Some((device, product_id, path)) = best {
114+
info!(
115+
"Selected mouse device: {} at {} (product: 0x{:04x})",
116+
device.name().unwrap_or("Unknown"),
117+
path.display(),
118+
product_id
119+
);
120+
return Ok(device);
121+
}
122+
97123
anyhow::bail!("No suitable mouse device found. Please specify a device path with --device")
98124
}
99125

0 commit comments

Comments
 (0)