Who is responsible of touchscreen coordinates adaptation?

Hello,

I’m using SDL 2.0.9 with patch 12581 to support eGalax touchscreen. I use SDL2 on Linux without x server

When I receiving events, I first get coordinates within the range of 0x0 … 1024x768 after after few, I receive coordinates within range of 0x0 … 4096x4096.

So I’m trying to understand what’s wrong and I’m wondering who is responsible to give me coordinates in relation with screen size.

Is it the SDL2?

Alain

Hi Alain,

Is there any way you can share some basic code so we can reproduce what you’re seeing?

@kotrunga, yes of course. Here is the code I used:

#include <stdbool.h>
#include <stdlib.h>

#include <SDL2/SDL.h>
#include <SDL2/SDL_events.h>

int main(void) {
	SDL_Window *WID_main_window;
	SDL_Renderer *WID_main_renderer;
    SDL_Event sdlevt;

    if ( SDL_Init( SDL_INIT_EVERYTHING) < 0 ) {
        exit(-1);
    }

	int video_driver_index = 1;
	int renderer_index = 1;

    SDL_RendererInfo info;

    setenv("SDL_VIDEODRIVER",SDL_GetVideoDriver(video_driver_index),1);

	SDL_GetRenderDriverInfo(renderer_index,&info);

	if(SDL_SetHint(SDL_HINT_RENDER_DRIVER, info.name) != SDL_TRUE)
	{
		printf("Fail to execute SDL_SetHint %s\n", SDL_GetError());
		exit(-1);
	}

	if ((WID_main_window = SDL_CreateWindow("tests", 0, 0, 1024, 768, SDL_WINDOW_SHOWN)) == NULL) {
		exit(-1);
	}

	if ((WID_main_renderer = SDL_CreateRenderer(WID_main_window, renderer_index, info.flags)) == NULL) {
		exit(-1);
	}

	if (SDL_SetRenderTarget(WID_main_renderer, NULL) != 0) {
		exit(-1);
	}
	SDL_SetRenderDrawColor(
			WID_main_renderer,
			0x80,
			0x80,
			0x80,
			SDL_ALPHA_OPAQUE);

	SDL_RenderClear(WID_main_renderer);

	SDL_RenderPresent(WID_main_renderer);

    SDL_ShowCursor(SDL_ENABLE);

    SDL_EventState(SDL_WINDOWEVENT,SDL_IGNORE);

    bool loop = true;
    while (loop) {
    	SDL_PollEvent(&sdlevt);

		if ( sdlevt.type == SDL_QUIT ) {
			loop = false;
		}

		if ((sdlevt.type == SDL_MOUSEBUTTONDOWN) ||
				(sdlevt.type == SDL_MOUSEBUTTONUP) ||
				(sdlevt.type == SDL_MOUSEMOTION)) {
			fprintf(stderr, "SDL event %d, x %d, y %d\n", sdlevt.type, sdlevt.button.x, sdlevt.button.y);
		}


		SDL_FlushEvent(SDL_MOUSEMOTION);

		SDL_Delay(50);
    }

    SDL_DestroyRenderer(WID_main_renderer);
    SDL_DestroyWindow(WID_main_window);
    SDL_Quit();

	return EXIT_SUCCESS;
}

We are using the native EETI native allpoint driver.

And here is the result I got:

Below I made touchs in the center of a full screen size of 1024x768, first touch is reported with (1023, 767), strange yet and then (1968, 1900), more or less the center of 4096x4096 touchpad resolution:

SDL event 1024, x 1023, y 767
SDL event 1025, x 1023, y 767
SDL event 1026, x 1023, y 767
SDL event 1024, x 1968, y 1900
SDL event 1025, x 1968, y 1900
SDL event 1026, x 1968, y 1900

Then I restarted the application and made 2 touchs in Bottom right corner:

SDL event 1024, x 1023, y 767
SDL event 1025, x 1023, y 767
SDL event 1026, x 1023, y 767
SDL event 1024, x 3902, y 3935
SDL event 1025, x 3902, y 3935
SDL event 1026, x 3902, y 3935

Then I restarted again and made few touchs in top left corner:

SDL event 1024, x 215, y 271
SDL event 1025, x 215, y 271
SDL event 1026, x 215, y 271
SDL event 1024, x 216, y 308
SDL event 1025, x 216, y 308
SDL event 1026, x 216, y 308
SDL event 1024, x 274, y 271
SDL event 1025, x 274, y 271
SDL event 1026, x 274, y 271
SDL event 1024, x 271, y 281
SDL event 1025, x 271, y 281
SDL event 1026, x 271, y 281

I think that I’m also supposed to see a cursor but nothing…
Alain