magic-mouse-driver
Open source ยท userspace driver for Linux

The Magic Mouse on Linux,
feeling like macOS.

Smooth scrolling with acceleration and momentum, two-finger swipes to switch workspaces, and stray touches ignored. One Python file, no kernel module.

Smooth scrolling with momentum

One-finger scrolling, vertical and horizontal, with acceleration. Content keeps gliding after you lift your finger; touch again to stop.

Two-finger swipe

Slide two fingers left or right to switch workspaces, like three fingers on a touchpad. The shortcut it sends can be changed.

Stray touches ignored

A grip on the sides of the mouse, a resting finger, and touches during a click or drag are not read as scrolling.

How it works

The hid-magicmouse kernel module exposes the raw touch data of the mouse surface, but its built-in scrolling is coarse and has no momentum. This driver sits in between.

  1. Magic MouseBluetooth
  2. hid-magicmousekernel module
  3. /dev/input/eventNgrabbed
  4. magicmouse_driver.pycomputes scroll and swipe
  5. /dev/uinputvirtual mouse and keyboard
  6. libinput / GNOMEdesktop
  1. Grabs the real device, so the desktop no longer sees the kernel's scrolling.
  2. Forwards pointer motion and clicks untouched.
  3. Computes scrolling from finger positions and sends it as high-resolution wheel events (1 unit = 1/120 of a notch).
  4. Sends a key combination through a virtual keyboard on a two-finger swipe.

If the driver stops or crashes, the grab is released and the mouse falls back to the kernel driver. When the mouse sleeps or disconnects, the driver waits and reconnects by itself.

Install

Tested on Ubuntu 24.04 (GNOME 46, Wayland) with a Magic Mouse 2 over Bluetooth. You need Python 3.11 or newer and a paired mouse.

Grant device access (once)

The driver reads /dev/input/event* and writes to /dev/uinput. After these commands, log out and back in.

sudo usermod -aG input "$USER"
echo 'KERNEL=="uinput", GROUP="input", MODE="0660"' | sudo tee /etc/udev/rules.d/99-uinput.rules
sudo udevadm control --reload && sudo udevadm trigger /dev/uinput

Install as a service

The script installs a systemd user service, starts it now and on every login, and copies the default config. Do not move the folder afterwards.

git clone https://github.com/xfrends/magic-mouse-driver.git
cd magic-mouse-driver
./install.sh

Check

The service should be active, and the log shows the device in use.

systemctl --user is-active magic-mouse-driver
journalctl --user -u magic-mouse-driver -n 5

Scroll direction follows Natural Scrolling in GNOME's mouse settings. To remove the driver, run ./uninstall.sh; the mouse goes straight back to the kernel driver. The full guide and troubleshooting are in the README (in Indonesian).

Configuration

Edit ~/.config/magic-mouse-driver/config.toml, then run systemctl --user reload magic-mouse-driver. The options changed most often:

OptionEffect
speedBase scroll speed
acceleration max_accelerationHow strongly fast movements are multiplied
inertia_timeHow long momentum glides (0.2 short, 0.5 long)
inertia = falseTurns momentum off
invert_x invert_yReverses the direction per axis
swipe_left swipe_rightKey combination sent on a two-finger swipe
swipe_distanceSwipe sensitivity (smaller is more sensitive)
zone_left zone_rightSurface area allowed to start a scroll; outside it a touch counts as grip

The default swipe actions are GNOME's workspace shortcuts (super+pagedown and super+pageup). Every option is in config.example.toml (comments in Indonesian).

Limitations

  • Final smoothness depends on the app: those that support high-resolution wheel events (GTK4, Firefox, Chromium/Electron on Wayland) feel smooth; older apps only receive whole notches.
  • The mouse reports over Bluetooth at about 90 Hz; that is the hardware limit for pointer motion.
  • A swipe sends its shortcut once per gesture; the animation does not follow your fingers 1:1 as on a touchpad.
  • The start of a horizontal scroll is held for about 80 ms to tell it apart from a swipe.
  • Other gestures (smart zoom, double-tap for Mission Control) are not implemented.