mac-precision-touchpad icon indicating copy to clipboard operation
mac-precision-touchpad copied to clipboard

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

Open expikr opened this issue 2 years ago • 2 comments

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

  • The ability to monitor for raw touch states in userspace enables the possibility of identifying 5~10 finger gestures without interfering with regular Precision Touchpad opreations.
  • Additionally, a temporary driver switch (maybe accessed via hotkey) could potentially enable pointer-mode for tablet-like drawing.

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

expikr avatar Feb 10 '22 15:02 expikr

cool!!!

EternalHXP avatar Jun 21 '22 06:06 EternalHXP

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

ClementGre avatar Sep 05 '23 21:09 ClementGre