From 611abdc8ce5baa317462945b6392347d05f42ef9 Mon Sep 17 00:00:00 2001 From: Kyle Arrington Date: Mon, 16 Nov 2026 21:41:48 -0600 Subject: [PATCH 1/2] HID: magicmouse: report the J813 trackpad's palms The J813 (MacBook Air 13" M5) trackpad sends the standard MTP report and classes its contacts like the T6041 and J616s ones: low byte of a record's second word, 2 and 3 for fingers, 6 and above for palms. Most J813 palms stay below the classed tool area of 1400 that the T6041 rule needs: recorded in normal use and while typing, 221 of 370 palm-classed contacts never passed it, and fingers reached 1560, so lowering it would not separate them. The class flickers to a palm for single reports on fingers (4 of 868), so on the J813 a contact also counts as a palm once two consecutive reports class it as one. That caught all 370 palms by their second report, and one finger, classed a palm for its last reports while lifting. As on the J616s, the J813 trackpad now also advertises ABS_MT_TOOL_TYPE and the full 16-bit range of its touch and width areas. Other machines are unchanged. Signed-off-by: Kyle Arrington --- drivers/hid/hid-magicmouse.c | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index cc079c42c5803..ea71bccd3896c 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -272,9 +272,13 @@ struct effect_job { * @tp26_button: Button state of the last Trackpad26 frame. * @mtp_c1fe: Whether the MTP trackpad sends the J700 C1FE report layout. * @mtp_palms: Whether the controller's contact classes are trusted for palms - * on the standard MTP report (T6041, J616s). + * on the standard MTP report (T6041, J616s, J813). * @mtp_palm_size: Whether a tool area alone marks an MTP contact as a palm. * @mtp_palm_ids: MTP contact IDs reported as palms until they lift. + * @mtp_palm_debounce: Whether two consecutive palm classes mark an MTP contact + * as a palm whatever its tool area (J813). + * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the + * previous report. * @ntouches: Number of touches in most recent touch report. * @scroll_accel: Number of consecutive scroll motions. * @scroll_jiffies: Time of last scroll motion. @@ -307,6 +311,8 @@ struct magicmouse_sc { bool mtp_palms; bool mtp_palm_size; DECLARE_BITMAP(mtp_palm_ids, U8_MAX + 1); + bool mtp_palm_debounce; + DECLARE_BITMAP(mtp_palm_classed, U8_MAX + 1); int ntouches; int scroll_accel; @@ -1002,27 +1008,46 @@ static u8 magicmouse_mtp_contact_id(const struct tp_finger *f) return le16_to_cpu(f->unknown1) & 0xff; } +/* + * The J813 (MacBook Air 13" M5) controller classes contacts the same way, but + * most of its palms stay below the classed tool area above: recorded on a J813 + * in normal use and while typing, 221 of 370 palm-classed contacts never passed + * 1400, and fingers reached 1560. Its class flickers to a palm for single + * reports on a finger (4 of 868 finger contacts), so there a contact also + * counts as a palm once two consecutive reports class it as one. That caught + * all 370 palms by their second report, and one finger, classed a palm for its + * last reports while lifting. + */ static void magicmouse_mtp_update_palms(struct magicmouse_sc *msc, const u8 *records, int count) { DECLARE_BITMAP(palms, U8_MAX + 1); + DECLARE_BITMAP(classed, U8_MAX + 1); const struct tp_finger *f; + bool palm_class; int i, tool; u8 id, class; bitmap_zero(palms, U8_MAX + 1); + bitmap_zero(classed, U8_MAX + 1); for (i = 0; i < count; i++) { f = (const struct tp_finger *)(records + i * sizeof(*f)); id = magicmouse_mtp_contact_id(f); class = le16_to_cpu(f->unknown2) & 0xff; tool = le16_to_int(f->tool_major); + palm_class = class >= MAGICMOUSE_MTP_PALM_CLASS_MIN; + if (palm_class) + __set_bit(id, classed); if ((msc->mtp_palm_size && tool > MAGICMOUSE_MTP_PALM_TOOL_MAJOR) || - (class >= MAGICMOUSE_MTP_PALM_CLASS_MIN && + (palm_class && tool > MAGICMOUSE_MTP_CLASSED_PALM_TOOL_MAJOR) || + (msc->mtp_palm_debounce && palm_class && + test_bit(id, msc->mtp_palm_classed)) || test_bit(id, msc->mtp_palm_ids)) __set_bit(id, palms); } bitmap_copy(msc->mtp_palm_ids, palms, U8_MAX + 1); + bitmap_copy(msc->mtp_palm_classed, classed, U8_MAX + 1); } static void report_finger_data(struct input_dev *input, int slot, @@ -1616,7 +1641,7 @@ static int magicmouse_setup_input_mtp(struct input_dev *input, /* * A palm's tool area on the T6041 and J616s trackpads exceeds * 5000 once scaled, so allow the full range of the record's - * 16-bit fields there. + * 16-bit fields on every trackpad whose palms are classed. */ int area_max = msc->mtp_palms ? 2 * S16_MAX : 5000; @@ -1643,7 +1668,7 @@ static int magicmouse_setup_input_mtp(struct input_dev *input, J314_TP_MAX_FINGER_ORIENTATION, 0, 0); } - /* The T6041, J616s and Trackpad26 controllers classify palms. */ + /* The T6041, J616s, J813 and Trackpad26 controllers classify palms. */ if (msc->mtp_palms || msc->mtp_tp26) input_set_abs_params(input, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); @@ -2658,12 +2683,19 @@ static int magicmouse_probe(struct hid_device *hdev, msc->mtp_c1fe = of_device_is_compatible(np, "apple,j700-multitouch"); msc->mtp_palm_size = !msc->mtp_c1fe && of_machine_is_compatible("apple,t6041"); + /* + * The J813 controller classes contacts the same way, and two + * consecutive palm classes mark its palms. + */ + msc->mtp_palm_debounce = !msc->mtp_c1fe && + of_machine_is_compatible("apple,j813"); /* * The J616s controller classes contacts the same way, but its * fingers reach a tool area of 2475, so only the class marks its * palms there. */ msc->mtp_palms = msc->mtp_palm_size || + msc->mtp_palm_debounce || (!msc->mtp_c1fe && of_machine_is_compatible("apple,j616s")); of_node_put(np); From c3ef84c764d9eec05f4e9515c9826c56921c6e23 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 17 Nov 2026 15:06:47 +0700 Subject: [PATCH 2/2] HID: magicmouse: report the J815 trackpad's palms too The J815 (MacBook Air 15" M5) has the J813's T8142 and MTP transport, and its trackpad sends the standard MTP report the previous commit reads on the J813, with the same contact classes. Take the J813's rule there as well: the controller's palm classes are trusted, and two consecutive palm classes mark a palm whatever its tool area. The pads differ: the J813 ADT's multi-touch hid-merge-personality is C1FD1,4, the J815's C1FD3,3 (a larger pad, firmware tpmtfw-j815.bin), so the rule was checked on a J815 recording (one contact line per lift): 30 s typing with both palms resting on the pad: 77 contacts the controller classed as palms, all 77 marked (36 by their second report); 15 short contacts with fewer palm classes, 11 of them marked, all with large tool areas (up to 5245) at the palms' edges. 30 s pointing, tapping and two-finger scrolling: 54 finger contacts, none marked and none with a palm class; the largest finger tool area was 1028, below the 1400 the area rule needs. (6 more contacts lifted in the first second: palms still resting from the typing phase, all classed as palms.) Assisted-by: Claude Opus 5.5 Signed-off-by: Nick Signed-off-by: Kyle Arrington --- drivers/hid/hid-magicmouse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c index ea71bccd3896c..b2ea417707bbf 100644 --- a/drivers/hid/hid-magicmouse.c +++ b/drivers/hid/hid-magicmouse.c @@ -276,7 +276,7 @@ struct effect_job { * @mtp_palm_size: Whether a tool area alone marks an MTP contact as a palm. * @mtp_palm_ids: MTP contact IDs reported as palms until they lift. * @mtp_palm_debounce: Whether two consecutive palm classes mark an MTP contact - * as a palm whatever its tool area (J813). + * as a palm whatever its tool area (J813, J815). * @mtp_palm_classed: MTP contact IDs the controller classed as palms in the * previous report. * @ntouches: Number of touches in most recent touch report. @@ -2685,10 +2685,12 @@ static int magicmouse_probe(struct hid_device *hdev, of_machine_is_compatible("apple,t6041"); /* * The J813 controller classes contacts the same way, and two - * consecutive palm classes mark its palms. + * consecutive palm classes mark its palms. The J815 (15-inch) + * sends the same standard report from its own, larger pad. */ msc->mtp_palm_debounce = !msc->mtp_c1fe && - of_machine_is_compatible("apple,j813"); + (of_machine_is_compatible("apple,j813") || + of_machine_is_compatible("apple,j815")); /* * The J616s controller classes contacts the same way, but its * fingers reach a tool area of 2475, so only the class marks its