lokxii / Mac-trackpad-mapper

A utility for Mac that maps finger position on trackpad to cursor location on Scnreen
MIT License
28 stars 3 forks source link

MultiTouch Identifiers Misidentification #15

Open romain-ker opened 10 months ago

romain-ker commented 10 months ago

First of all, thank you for this cool project. I'm not at all in app development and have only experience in python and a tiny bit of web dev. Excuse me in advance if I don't understand every subtility of the code.

I compiled and installed the mapper with no issue, managed to grant permissions but the app doesn't map the trackpad at all when started. The menu is displaying well so I guessed it wasn't a swift problem but rather a C/C++ issue.

I edited a bit the util file to add some dummy prints to try to have some clues about the place where the problem occurs:

    for (CFIndex i = 0; i < CFArrayGetCount(deviceList); i++) {
        MTDeviceRef device = (MTDeviceRef)CFArrayGetValueAtIndex(deviceList, i);
        int familyId;
        MTDeviceGetFamilyID(device, &familyId);

        // Dummy print 1
        printf("familyId: %d\n", familyId);
        printf("Trackpad found\n");

        if (
            familyId >= 98
            && familyId != 112 && familyId != 113  // Magic Mouse 1&2 / 3
        ) {

            // Dummy print 2
            printf("Starting Callbacks\n");

            MTRegisterContactFrameCallback(device, (MTFrameCallbackFunction)trackpadCallback);
            MTDeviceStart(device, 0);
        }
    }

Here is the output of these small modifications when I run the code, during the listing of devices part:

familyId: 176
Trackpad found
Starting Callbacks
*** Recognized (0xb0) family*** (60 cols X  2 rows)
familyId: 113
Trackpad found

However, I had disconnected my external MagicTrackpad for the experimentation to avoid disturbing anything, and what a surprise ! I still had 2 multitouch devices listed. One of them is (n°176) and (in theory) is able to use absolute positioning The other one (n°113) is, according to the comments, a Magic Mouse 2 (spoiler, it's not)

I finally managed to identify the problem. I'm running the code on a MacBook Pro M2 13" 2022 with macOS Sonoma 14.1.2 On this device, the TouchBar is also a MultiTouch compatible device. Here, my TouchBar is the device n°176 whereas my actual internal trackpad is n°113.

The fun part being that while the actual trackpad is not taken into account by the app due to the anti MagicMouse update (#14), the app is working really well on the TouchBar. I can fully control my cursor from the touchbar, the small height and wide width of the device trying to match the screen size. I will definitely break records on osu! with this setup (no).

For my usage, I simply removed the MagicMouse catch and it's working like a charm. I remember that I might encounter problem if I own one of these devices one day, but that's not that important.

Thank you once again for creating this nice app

lokxii commented 10 months ago

I have been super busy in the past few months (till now), sorry for only noticing your issue after 8 days.

A solution to this problem is to have an updated list of familyId of all multitouch compatible devices, such that this app can hook callback to the correct devices. With the list, we may be able to

  1. have multiple devices connected
  2. be able to choose which device to hook callback

I wonder is there a predefined list of devices available to developers. Tbh I think we may need to reverse engineer familyID of all existing devices. It requires a community to do it but obviously there is no community surrounding this project.

Nevertheless, I should really spend some time fixing some of the issues relating to (re)connecting devices later.