Weird problem with touch screen, X11 and Raspberry pi 4

My Setup:
Raspberry pi 4, 2GB RAM
5 inch capacitive HDMI touch screen
OS: Raspbian configured to boot to CLI to save resources
SDL Version: 2.0.14
SDL Image Version: 2.0.5
SDL TTF Version: 2.0.15

SDL is configured as default “just the ./configure, no extra parameters”

The screen is connected to HDMI to hdmi0 of the Raspberry pi 4.
The data usb of the screen is connected to a USB2.0 of the raspberry pi.
When booting to Desktop the touchscreen works fine.

At start (configured in crontab) I let 7 seconds then I start my program with startx,
which should start the program as root.

I want to get mouse events from the touch screen (click & x/y coords),
for now I’m printing the x/y coords in the screen when a SDL_MOUSEBUTTONDOWN event is received.

When the program starts, I send a placeholder text to where the coords should be so when an event happens I can see an update, When I touch anywhere in the screen the coords I get are the coords of the center of the screen, ALWAYS, which means I get touch events from the screen, but not coordinates are given.

I thought that the fact I didn’t start the Desktop environment should be bothering SDL in some way, wich is weird because I’m getting touch events.

Now here start the weird part:
Then just to test different things, I plugged a regular USB mouse, And weirdly enough this one worked as expected, I moved the mouse and when I clicked the coords in the screen updated with every click. Even weirder is that if I move the mouse (without clicking it) and touch the screen I get everytime the coords of the mouse.

Now If i reboot and go to the desktop environment and start my program the touch screen works as intended (you can see the arrow move when I touch the screen) showing the coordinate of where I touched. So the touchscreen works fine with my program, It’s just it doesn’t work if I boot to CLI and then startx my program, except if it’s a real USB mouse, then it works anyway…

“lsusb” shows it as: Bus 001 Device 003: ID 1a86:e2e3 QinHeng Electronics USB2IIC_CTP_CONTROL

it can be found as /dev/hidraw0

if I then do “cat /dev/input/mice” the output shows stuff as I move/click the finger over the screen so the data is getting to the OS (obviously, I mean I used it fine with the desktop running so the screen it’s working)

I tried getting the events of:

  • SDL_MouseButtonEvent
  • SDL_MouseMotionEvent (as it acts as a mouse)
  • SDL_TouchFingerEvent (as it’s actually a touchscreen)
  • SDL_MultiGestureEvent (as it’s a capacitive touchscreen wich shoud be able to get multifinger gestures I guess (?) )

Any Ideas? It looks like It has something to do with startx just starting the application, but the USB mouse shouldn’t work either…

what do you use to get the x/y coordinates?