Battery monitor for Apple Magic Trackpad on Linux (Bluetooth).
A lightweight daemon that reads battery percentage from Apple Magic Trackpad over Bluetooth, where the kernel reports 0%.
Linux's hid_magicmouse kernel driver implements battery reporting only over USB. When connected via Bluetooth, the kernel power_supply subsystem always shows 0% — even though the device does report battery status over HID.
This daemon reads the battery directly from the hidraw device using the HIDIOCGINPUT ioctl to fetch HID Input Report 0x90. The 3-byte report contains:
| Byte | Contents |
|---|---|
| 0 | Report ID (0x90) |
| 1 | Status flags (bit 1 = charging) |
| 2 | Battery capacity (0–100%) |
The daemon polls every 5 minutes and writes the result as JSON for easy integration with status bars like Waybar.
yay -S magic-trackpad-battery-git
# Reconnect the Trackpad once so the new udev rule is applied.
systemctl --user enable --now magic-trackpad-battery
systemctl --user enable --now magic-trackpad-autoconnect.timersystemctl --user disable --now magic-trackpad-battery
systemctl --user disable --now magic-trackpad-autoconnect.timer
yay -R magic-trackpad-battery-git
sudo udevadm control --reload-rules
systemctl --user daemon-reloadFor development or non-Arch systems:
git clone https://github.com/mmarfil/magic-trackpad-battery.git
cd magic-trackpad-battery
make installThen install the udev rule (requires sudo) and enable the service:
sudo rm -f /etc/udev/rules.d/99-magic-trackpad.rules # remove the superseded rule, if present
sudo install -Dm644 72-magic-trackpad.rules /etc/udev/rules.d/72-magic-trackpad.rules
sudo udevadm control --reload-rules
# Reconnect the Trackpad once so the new rule is applied.
systemctl --user daemon-reload
systemctl --user enable magic-trackpad-battery
systemctl --user restart magic-trackpad-battery
systemctl --user enable --now magic-trackpad-autoconnect.timerTo remove a manual install:
make uninstall
sudo rm -f /etc/udev/rules.d/72-magic-trackpad.rules
sudo udevadm control --reload-rulesAdd a custom module to your Waybar config (~/.config/waybar/config.jsonc):
Add it to your modules list (e.g., "modules-right"). The module hides itself automatically when the trackpad is disconnected.
The helper displays the fixed label MTP and uses Pango markup to dim it, so "markup": true is required.
The package includes an auto-connect script that periodically attempts to reconnect paired Magic Trackpad devices via Bluetooth. It runs as a systemd timer (every 30 seconds) and uses bluetoothctl to discover and connect paired devices.
The script auto-discovers any paired device with "Magic Trackpad" in its name — no MAC address configuration needed. You can also set MAGIC_TRACKPAD_MAC to target a specific device.
- Device discovery: Scans
/sys/class/hidraw/for a Bluetooth (HID_ID=0005) Magic Trackpad using themagicmousedriver - hidraw access: Opens
/dev/hidrawNand issuesHIDIOCGINPUTioctl (read Input Report by ID) - Battery parsing: Report
0x90returns[id, status, capacity]— capacity is percentage, status bit 1 is charging - JSON output: Writes connected state as
{"percentage": N, "charging": bool, "connected": true, "device_name": str, "updated_at": epoch}atomically via rename. Disconnected state omitsdevice_name. - Low battery alerts: Sends desktop notifications via
notify-sendat 20%, 15%, 10%, 5% - Reconnection: When the device disconnects, the daemon re-scans every 30 seconds
The udev rule grants hidraw access to the active local session through systemd-logind's uaccess ACL. No persistent input-group membership is required. Reconnect the Trackpad after installing or changing the rule.
| File | AUR package | Manual install |
|---|---|---|
magic-trackpad-battery |
/usr/bin/ |
~/.local/bin/ |
magic-trackpad-battery-waybar |
/usr/bin/ |
~/.local/bin/ |
magic-trackpad-connect |
/usr/bin/ |
~/.local/bin/ |
magic-trackpad-battery.service |
/usr/lib/systemd/user/ |
~/.config/systemd/user/ |
magic-trackpad-autoconnect.service |
/usr/lib/systemd/user/ |
~/.config/systemd/user/ |
magic-trackpad-autoconnect.timer |
/usr/lib/systemd/user/ |
~/.config/systemd/user/ |
72-magic-trackpad.rules |
/usr/lib/udev/rules.d/ |
/etc/udev/rules.d/ (sudo) |
| Battery JSON | $XDG_RUNTIME_DIR/magic-trackpad-battery.json |
same |
| Device | Status |
|---|---|
| Magic Trackpad 2 (A1535) | Confirmed working |
| Magic Trackpad (USB-C) | Expected to work over Bluetooth; hardware confirmation pending |
"Permission denied" opening hidraw:
- Ensure the udev rule is installed and rules are reloaded
- Reconnect the trackpad (udev rules apply on device connect)
- Check:
getfacl /dev/hidrawN— the active user should have read/write access
Device not found:
- Find the address:
bluetoothctl devices Paired | grep -i 'Magic Trackpad' - Verify the connection:
bluetoothctl info <MAC>should showConnected: yes - Check the HID metadata:
grep -rE '^(DRIVER=magicmouse|HID_ID=0005:|HID_NAME=.*Magic Trackpad)' /sys/class/hidraw/*/device/uevent - The
hid_magicmousemodule must be loaded:lsmod | grep hid_magicmouse
JSON file not updating:
- Check service status:
systemctl --user status magic-trackpad-battery - Check logs:
journalctl --user -u magic-trackpad-battery -f
Waybar module not showing:
- The module is hidden when the trackpad is disconnected (empty
textfield) - Verify the JSON:
cat "$XDG_RUNTIME_DIR/magic-trackpad-battery.json" - Run the helper manually:
magic-trackpad-battery-waybar
make test # deterministic, hardware-independent tests
make probe # detect a connected Bluetooth Magic Trackpad- Python 3 (standard library only — no pip packages)
notify-send(fromlibnotify) for low battery alertsbluetoothctl(frombluez-utils) for auto-connect- systemd (for the user service and timer)
- A Bluetooth stack (BlueZ) with the trackpad paired and connected
MIT