After enabling the hint SDL_HINT_TRACKPAD_IS_TOUCH_ONLY on macOS, interacting with the trackpad will generate SDL_TouchFingerEvent.
In the SDL_TouchFingerEvent struct, the XY coordinates are normalized to 0~1, which is acceptable for touchscreens, but not for trackpads:
- For touchscreens, the coordinates are mapped to the whole window, which we know the size/ratio.
- For trackpads, the coordinates are mapped to the trackpad, which the size/ratio is unknown.
This can cause problems.
For example, for a trackpad with a 2:1 aspect ratio, moving the finger one centimeter right may change the X coordinate by n amount, but moving one centimeter down will change the Y coordinate by 2 * n.
Without knowing the original trackpad's aspect ratio, the changes in X and Y coordinates are just not comparable.
My suggestion is to store the device's aspect ratio as a floating number somewhere, for example in struct SDL_touch:
|
typedef struct SDL_Touch |
|
{ |
|
SDL_TouchID id; |
|
SDL_TouchDeviceType type; |
|
int num_fingers; |
|
int max_fingers; |
|
SDL_Finger **fingers; |
|
char *name; |
|
} SDL_Touch; |
And provide an API (e.g. SDL_GetTouchDeviceAspectRatio) to retrieve it.
For macOS, the ratio might be calculated with deviceSize.
After enabling the hint
SDL_HINT_TRACKPAD_IS_TOUCH_ONLYon macOS, interacting with the trackpad will generateSDL_TouchFingerEvent.In the
SDL_TouchFingerEventstruct, the XY coordinates are normalized to 0~1, which is acceptable for touchscreens, but not for trackpads:This can cause problems.
For example, for a trackpad with a 2:1 aspect ratio, moving the finger one centimeter right may change the X coordinate by
namount, but moving one centimeter down will change the Y coordinate by2 * n.Without knowing the original trackpad's aspect ratio, the changes in X and Y coordinates are just not comparable.
My suggestion is to store the device's aspect ratio as a floating number somewhere, for example in
struct SDL_touch:SDL/src/events/SDL_touch_c.h
Lines 26 to 34 in 6980325
And provide an API (e.g.
SDL_GetTouchDeviceAspectRatio) to retrieve it.For macOS, the ratio might be calculated with
deviceSize.