Skip to content

Source aspect ratio information missing in TouchFingerEvent generated by trackpads #12391

@AlexGuo1998

Description

@AlexGuo1998

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions