-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
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:
Lines 26 to 34 in 6980325
| 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.