Touch Screen - SDL 2.0.20

I have a Display with a capacitive Touch screen on my embedded device, running SDL 2.0.20 but i can’t get the correct x and y touch position, it always returns x and y with inf, despite the event getting the correct position on ABS_MT_POSITION_X and ABS_MT_POSITION_Y.

Using testgesture as a base:

INFO: SDL EVENT: Window 1 hidden
INFO: SDL EVENT: Window 1 gained keyboard focus
INFO: SDL EVENT: Window 1 shown
INFO: SDL EVENT: ABS_MT_POSITION_X: x=330
INFO: SDL EVENT: ABS_MT_POSITION_Y: y=137
INFO: SDL EVENT: TOUCH
INFO: SDL EVENT: SDL_GetFinger(): fingerid=116, x: inf, y: inf
INFO: SDL EVENT: fingerdown: fingerid=116, x=1, y=1
INFO: SDL EVENT: Finger: down touch=13, finger=116, x=1.000000, y=1.000000, dx=0.000000, dy=0.000000, pressure=1.000000
INFO: SDL EVENT: TOUCH
INFO: SDL EVENT: SDL_GetFinger(): fingerid=116, x: inf, y: inf
INFO: SDL EVENT: fingerup: fingerid=116, x=2147483647, y=2147483647
INFO: SDL EVENT: Finger: up touch=13, finger=116, x=1.000000, y=1.000000, dx=0.000000, dy=0.000000, pressure=1.000000

I can’t figure out why x and y on

int
SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
              SDL_bool down, float x, float y, float pressure)

get inf values?

I think tfinger.x and event.tfinger.y should have the correct value but they do not.
I have not tested SDL 3 cause testgesture is missing.

In case you need more info about the environment:

  • Ubuntu 22.04
  • SDL 2.0.20
  • GBM / WAYLAND (No Desktop)

The mouse is working fine.

Any ideas?

SDL 2.0.20? This is super old version. Try with the current stable version, ie. SDL 2.28.5.

True, but i need to stick with the distro version.

It looks like the new versions have the same issue. It tries to normalize x and y when it should not in the case of non-DESKTOP.

range_x and range_y are 0, this break here (SDL3 version and possibly all versions):

This hack fixes the issue in my case:

                            #if 0
                            norm_x = (float)(item->touchscreen_data->slots[j].x - item->touchscreen_data->min_x) /
                                (float)item->touchscreen_data->range_x;
                            norm_y = (float)(item->touchscreen_data->slots[j].y - item->touchscreen_data->min_y) /
                                (float)item->touchscreen_data->range_y;
                            #else
                            norm_x = (float)item->touchscreen_data->slots[j].x;
                            norm_y = (float)item->touchscreen_data->slots[j].y;
                            #endif

maybe a real fix should work on all cases, non-Desktop / Desktop and resistive touch :

item->touchscreen_data->range_x = abs_info.maximum - abs_info.minimum;
if (!item->touchscreen_data->range_x)
   item->touchscreen_data->range_x = 1;

item->touchscreen_data->range_y = abs_info.maximum - abs_info.minimum;
if (!item->touchscreen_data->range_y)
   item->touchscreen_data->range_y = 1;


I haven’t tested so far…