# hid-magicmouse with Force Touch This is a patched `hid_magicmouse` for the Apple Magic Trackpad 2. It adds two things: a two-stage Force Touch click, and one small haptic tick when a finger first lands on the trackpad. The new module parameters are `force_click`, `touch_haptic`, and `force_button`. Thresholds, debounce, waveforms, and haptic strength are fixed in the source. ## Behaviour When `force_click` is on, the driver takes over clicking with feature report `0x21`. Pressure from the touch report goes through a Schmitt trigger: - `70` starts the normal click, `40` releases it - `165` adds the second stage, `125` drops back to the normal click - transitions need to hold for 15 ms The normal click is `BTN_MOUSE` / `BTN_LEFT`. The second stage emits `BTN_TRIGGER_HAPPY1` on a small `Apple Force Touch Button` input device; the touchpad keeps the `MSC_RAW` values `1`, `2`, and `0` for click, force, and release. libinput drops unknown buttons on touchpad devices, so compositors see the force stage from the separate device. `force_button` picks the EV_KEY code that device sends: `704` by default, `274` for middle-click, or a keyboard key such as `30` for `KEY_A`. The force key is still emitted if host-click setup fails. With `force_button` set to anything other than `704`, the stage-1 left click is held briefly instead of being sent immediately. If force arrives first, it is cancelled; otherwise it becomes a normal click on release or once the finger moves 30 units. The haptic tick fires on a fresh contact and is rate-limited to 120 ms. It uses output report `0x53`, with no trailing release report. On USB-C trackpads the actuator is a sibling HID interface; the driver finds it by looking for that output report. `INPUT_PROP_BUTTONPAD` is left as-is. `INPUT_PROP_PRESSUREPAD` is not set, because the pressure axis is not useful for libinput touch detection. ## Compositors Bind the force stage to `mouse:704`. In Hyprland that is a normal mouse bind: ```lua hl.bind("mouse:704", hl.dsp.exec_cmd("notify-send 'force-touch'")) ``` KWin may report the same button as `ExtraButton24`, depending on the version. Set `force_button=274` if you want force to be a normal middle click instead. A keyboard code works too; bind that key normally in your compositor. To check the raw event, pick `Apple Force Touch Button` in `sudo evtest`. The force device is separate from the touchpad because libinput ignores buttons it does not know about on clickpad devices. ## Build The Makefile uses whatever kernel build tree you point it at. It reads `CONFIG_CC_IS_CLANG` from that kernel's config, so it does not care if the kernel was built with GCC or Clang. ```sh make clean make W=1 ``` For another kernel: ```sh make KDIR=/path/to/linux-build clean make KDIR=/path/to/linux-build W=1 ``` The source is based on v7.2. High-resolution wheel events put the practical baseline at mainline v5.0 or newer. `compat/kernel-compat.h` covers the timer renames in later kernels. ## Install ```sh sudo dkms add . sudo dkms install hid-magicmouse-force/0.2 -k "$(uname -r)" sudo depmod -a ``` It installs as `hid_magicmouse`, under `/updates/dkms/`. Check with: ```sh modinfo hid_magicmouse | grep -E '^(filename|name|parm):' ``` ## Runtime settings All three parameters are writable: ```sh P=/sys/module/hid_magicmouse/parameters echo 0 | sudo tee "$P/touch_haptic" echo 1 | sudo tee "$P/force_click" echo 274 | sudo tee "$P/force_button" echo 30 | sudo tee "$P/force_button" # KEY_A ``` `force_button` accepts any EV_KEY code from `1` to `KEY_MAX` and changes the next force stage. `force_click` reconfigures the hardware when it changes. `touch_haptic` takes effect on the next touch. ## Sources - [nexustar/linux-hid-magicmouse](https://github.com/nexustar/linux-hid-magicmouse) - [libinput touchpad dispatch](https://gitlab.freedesktop.org/libinput/libinput/-/blob/master/src/evdev-mt-touchpad.c) - [libinput fallback dispatch](https://gitlab.freedesktop.org/libinput/libinput/-/blob/master/src/evdev.c) - [systemd input_id](https://github.com/systemd/systemd/blob/main/src/udev/udev-builtin-input_id.c) - [Linux input event codes](https://docs.kernel.org/input/event-codes.html)