A small Rust program that repurposes a trackball’s back button (BTN_SIDE) into a scroll toggle. When you press and hold the back button, moving the trackball will produce scroll events instead of pointer movements. Releasing the back button returns it to normal movement mode.
Many trackball devices lack a dedicated scroll wheel, forcing you to use a separate method (like a scroll ring or on-screen scrollbar). By intercepting the physical back button and using it to toggle “scroll mode,” this program makes your trackball more versatile and efficient:
- Convenience: No need for separate scroll rings, buttons, or keyboard shortcuts for scrolling.
- Customization: Easilyt adjust scrolling speed and pointer movement rate to your preference.
- Grab the physical device via [evdev] so the back button doesn’t trigger a browser or window manager “Back” action.
- Create a virtual device via [uinput], which the OS sees as a legitimate mouse with movement, scroll, and click capabilities.
- Intercept input events from the real trackball:
- Back Button Press: Toggles scroll mode on or off.
- Pointer Movement:
- If scroll mode is off, forward movement events (scaled by a
MOVE_RATE
) to the virtual device as normal pointer movement. - If scroll mode is on, transform the movement events into vertical and horizontal scroll events (with optional fractional accumulation for smoother scrolling).
- If scroll mode is off, forward movement events (scaled by a
- Click Events: Forward BTN_LEFT and BTN_RIGHT events to the virtual device so that clicking still works as expected.
- Linux (with
/dev/input
and/dev/uinput
) - Rust (1.60+ recommended)
- Permissions to read from
/dev/input/event*
and write to/dev/uinput
(commonly root or special udev rules)
- Build
cargo build --release
- Run (as root)
sudo ./target/release/trackball-emulation
- Move the trackball normally.
- Press the back button to toggle scroll mode; move the trackball to scroll.
- Release the back button to revert to normal pointer movement.
If you want this to run automatically at boot:
- Copy the compiled binary to a system location, e.g.:
sudo cp target/release/trackball-emulation /usr/local/bin/trackball-emulation
- Create a systemd unit file
/etc/systemd/system/trackball-scroller.service
:[Unit] Description=Trackball Scroll Emulation After=multi-user.target [Service] Type=simple ExecStart=/usr/local/bin/trackball-emulation Restart=always User=root Group=root [Install] WantedBy=multi-user.target
- Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable trackball-scroller.service sudo systemctl start trackball-scroller.service
- Check status:
systemctl status trackball-scroller.service
- MOVE_RATE: Adjust the pointer speed for normal movement.
- SCROLL_FACTOR: Adjust how quickly scrolling accumulates ticks. Decrease for smoother/slower scrolling, increase for faster/more immediate scrolling.
- Additional Buttons: Forward other buttons or shortcuts by matching the appropriate
Key::BTN_*
events.
Happy Scrolling!