imbushuo / mac-precision-touchpad

Windows Precision Touchpad Driver Implementation for Apple MacBook / Magic Trackpad
Other
9.14k stars 571 forks source link

Userspace implementation of three-finger-drag via WM_INPUT and mouse_event #469

Open expikr opened 2 years ago

expikr commented 2 years ago

Issue

Windows Precision Touchpad implementation lacks the logic of three-finger drag, and since this driver project is merely a translation layer to connect to the Precision-Touchpad interface it is impossible to implement it driverside.

Solution

Have a userspace program that monitors WM_INPUT messages in the background and synthesize mouse_event calls. The program should also allow one-click disabling of all Precision-Driver three-finger gestures as not to cause interference.

Implementation Sketch

  1. Userspace program configures Precision Driver options to "Do Nothing" for all three-finger gestures
  2. Userspace program calls RegisterRawInputDevices with the correct usage (need to verify, I believe it should be DIGITIZER:TOUCHPAD), and with RIDEV_INPUTSINK (monitor in background) + RIDEV_DEVNOTIFY (listen for pertinent device change) flags
  3. Upon receiving WM_INPUT_DEVICE_CHANGE arrival notices, userspace program calls GetRawInputDeviceInfo for each handle received to identify which handle belongs to the device that we wish to monitor, then fetch the preparsed data for that device via another GetRawInputDeviceInfo call.
  4. For each incoming WM_INPUT message:
    1. Call GetRawInputData with flag RID_HEADER to check that the handle belongs to the device we wish to monitor, discard if not.
    2. Call GetRawInputData with flag RID_INPUT to fetch the content for the messages coming from the monitored device
    3. Use the preparsed data to interpret the touch state, evaluate whether user is interacting with the three-finger-drag gesture
    4. synthesize the corresponding motion and action (accounting for user sensitivity preferences) using mouse_event, which broadcasts mouse motion rather than sending them to a specific app as SendInput would.
    5. NOTE: mouse_event cannot send to higher-privilege processes, so in order to interact with elevated windows the Userspace program must be launched with the same or higher privileges. Installing the userspace process as a background service with SYSTEM privileges should account for all possible interactions.

Extension

Sample UX proof-of-concept: image

Alternatively, instead of a hotkey switch, can just detect five finger as "quick jot mode" and the sixth finger acting as absolute-coordinate drawing within the region subset:

image

AB#812

EternalHXP commented 2 years ago

cool!!!

ClementGre commented 1 year ago

Hi, I developped an app that does exactly this, enabling three fingers drag on any Windows Precision compatible touchpad: https://github.com/ClementGre/ThreeFingersDragOnWindows.