Skip to content

HID: magicmouse: add palm rejection for the J700 trackpad - #155

Open
LiamRay11 wants to merge 1 commit into
omacom:integration/aurorafrom
aurora-silicon:fix/j700-palm-rejection
Open

LiamRay11 wants to merge 1 commit into
omacom:integration/aurorafrom
aurora-silicon:fix/j700-palm-rejection

Conversation

@LiamRay11

Copy link
Copy Markdown

The J700 (MacBook Neo) trackpad only reported finger positions, so a palm landing on or resting on the pad while typing moved the pointer.

Report the touch and tool areas and the orientation the controller provides, and report palms as MT_TOOL_PALM: contacts the controller classifies as a palm, and contacts whose tool area grows past palm size, which stay palms until they lift. Thumbs and fingers still move the pointer.

The J700 (MacBook Neo) trackpad only reported finger positions, so a
palm landing on or resting on the pad while typing moved the pointer.

Report the touch and tool areas and the orientation the controller
provides, and report palms as MT_TOOL_PALM: contacts the controller
classifies as a palm, and contacts whose tool area grows past palm size,
which stay palms until they lift. Thumbs and fingers still move the
pointer.

Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome work Liam!

@3j27

3j27 commented Oct 24, 2026

Copy link
Copy Markdown

Thanks for this, tested on a MacBook Neo against Omarchy 4.0.0.r7235, works great:

The Apple MTP multi-touch device was bound to magicmouse and exposed contact-size and tool-type axes. A first 30-second capture received no touch events and was inconclusive. A repeated 45-second live trackpad-only capture recorded:

Measurement Result
Touch frames 342
Palm tool-type transitions (MT_TOOL_PALM) 16
Finger tool-type transitions 17
Peak reported tool width 10,478

These counts are classification transitions, not necessarily distinct palm/finger contacts. No keyboard input was captured. This confirms live hardware palm classification through the patched driver. The user also reported that accidental movement seemed improved.

This fixes one of the last major usability problems I've experienced with my setup

@maralcbr maralcbr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LiamRay11 thanks, the approach is sound, and @3j27's capture shows the controller's palm class coming through live. The parsing is safe:

  • the C1FE validator pins the length to 32 + 30*N + 8 with N ≤ 16, so magicmouse_c1fe_update_palms() (hid-magicmouse.c:943-960) only reads records that are in the report, at the same 30-byte stride as the main loop;
  • the 256-bit map covers every u8 contact ID;
  • BIT(class) is guarded.

The non-C1FE trackpads keep the same axes, pressure and reports.

Before I approve, I'd like three things confirmed, because this is the Neo's only pointing device:

  1. libinput's size rules now apply to the J700. libinput's Apple*MTP* quirk sets AttrTouchSizeRange=150:130 and AttrPalmSizeThreshold=1600 (50-system-apple.quirks). Both only take effect once the device advertises ABS_MT_TOUCH_MAJOR, and this PR turns that on (:1349-1350). So libinput will now ignore contacts whose touch size stays under its threshold, and treat any contact whose TOUCH_MAJOR passes 1600 as a palm, separately from the driver's 4400 tool-width rule. M1/M2 trackpads already run with this quirk, so it may be fine, but the J700's units need checking. Could you confirm with the libinput we ship that light touches, taps, two-finger scroll, click-and-drag and three-finger gestures all still work, and post the usual TOUCH_MAJOR range for fingers and thumbs?
  2. Records with zero touch area. The C1FE path used to keep records with touch_major == 0, and the old comment said the area is zero on some real contacts. Now they're skipped (:1055). Because of INPUT_MT_DROP_UNUSED, a skipped touching record ends its slot, and the pointer jumps or a tap goes missing. Can you confirm from a capture that touching records (state 4) always have a non-zero touch_major?
  3. Palm mark on a reused ID. The sticky mark carries over while the ID shows up in any record, lift-off records included (:951-959). If the controller reuses an ID for a new finger without a frame where the ID is absent, that finger starts as a palm. Nothing clears the map on open, close or reset either. Either confirm IDs always drop out for a frame before reuse, or clear the mark when a record for that ID is in a non-touching state.

Not blocking:

  • le16_to_int() sign-extends, so a raw value with the top bit set would read as a negative size. That's fine if the controller never sends one.
  • Pointer emulation still counts palms in BTN_TOUCH and the finger-count buttons. libinput uses the slot tool type, so this only matters for legacy consumers.

CI hasn't run on this head yet. The merge queue runs the required checks.

@chriskearney chriskearney left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 68df87370abac4e227936552dd9be2252972e551. Holding approval pending the contact-lifecycle and userspace-validation questions in @maralcbr's review; the existing live capture demonstrates palm classification, but does not settle those questions.

I independently reproduced the lifecycle concern using the unmodified magicmouse_c1fe_update_palms() and classification/validation helpers in a host harness (bitmap/endian shims, ASan+UBSan):

  1. ID 7, touching state 4, raw tool_major=2201: sticky palm bit set.
  2. ID 7, non-touching state, zero touch/tool area: sticky bit remains set.
  3. ID 7, touching state 4, finger class 2, raw tool_major=100: still reported as a palm.

An intervening report without that ID clears the bit. The result reproduces for all 256 IDs. This is a synthetic sequence, not evidence that a J700 actually reuses IDs this way. The code currently depends on an absent-ID frame, rather than clearing at lift as its comment promises (lines 943–959). Please clear the sticky state at the appropriate contact/session boundary and cover reuse, or provide capture evidence establishing the necessary lifecycle invariant, including reopen/resume.

Separately, the new zero-area filtering and advertised touch-size axes still need confirmation with the shipped libinput: state-4 zero-area behavior, light touches/taps, scroll, drag and multi-finger gestures. The earlier position-only path accepted zero-area contacts, so classification counts alone do not establish compatibility.

Positive checks: exact report-length/count validation, all 256 class values (including guarded shifts), threshold boundaries and absence clearing passed in the host harness without sanitizer findings. Non-C1FE pressure/axis behavior is preserved by inspection. No kernel build or hardware operation performed; this is not hardware qualification.

@bricolage

Copy link
Copy Markdown

Same symptom on a 16-inch MacBook Pro M1 Pro (apple,j316s, Linux 7.2.11.aurora14): a palm resting by the thumb moves the pointer while typing, and hand contact on the pad also registers clicks.

This change looks gated on the C1FE layout (J700). j316s uses the J314-style layout, which per the comment above already reports touch/tool areas — is there an equivalent palm classification for the J314-style pads, or would that need a separate change?

Happy to test on j316s if a build applies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants