mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-16 11:06:49 +01:00
Fixed bug 3871 - Touch events are not normalised on X11
Trent Gamblin The documentation for SDL_TouchFingerEvent says that the x and y coordinates are normalised between 0-1. I've found that to be true on Windows, Android and iOS but on X11 they are in pixel coordinates. This patch fixes the issue. This was the cleanest way I could do it with what was available without changing things around a lot but you may know a better way.
This commit is contained in:
parent
b53c35df43
commit
c0019b7f49
@ -73,6 +73,24 @@ xinput2_version_atleast(const int version, const int wantmajor, const int wantmi
|
||||
{
|
||||
return ( version >= ((wantmajor * 1000) + wantminor) );
|
||||
}
|
||||
|
||||
static void
|
||||
xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
|
||||
double in_x, double in_y, float *out_x, float *out_y)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < videodata->numwindows; i++) {
|
||||
SDL_WindowData *d = videodata->windowlist[i];
|
||||
if (d->xwindow == window) {
|
||||
*out_x = in_x / (d->window->w-1);
|
||||
*out_y = in_y / (d->window->h-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// couldn't find the window...
|
||||
*out_x = in_x;
|
||||
*out_y = in_y;
|
||||
}
|
||||
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
|
||||
|
||||
void
|
||||
@ -171,22 +189,31 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
|
||||
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
|
||||
case XI_TouchBegin: {
|
||||
const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
|
||||
float x, y;
|
||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||
xev->event_x, xev->event_y, &x, &y);
|
||||
SDL_SendTouch(xev->sourceid,xev->detail,
|
||||
SDL_TRUE, xev->event_x, xev->event_y, 1.0);
|
||||
SDL_TRUE, x, y, 1.0);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case XI_TouchEnd: {
|
||||
const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
|
||||
float x, y;
|
||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||
xev->event_x, xev->event_y, &x, &y);
|
||||
SDL_SendTouch(xev->sourceid,xev->detail,
|
||||
SDL_FALSE, xev->event_x, xev->event_y, 1.0);
|
||||
SDL_FALSE, x, y, 1.0);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case XI_TouchUpdate: {
|
||||
const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
|
||||
float x, y;
|
||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||
xev->event_x, xev->event_y, &x, &y);
|
||||
SDL_SendTouchMotion(xev->sourceid,xev->detail,
|
||||
xev->event_x, xev->event_y, 1.0);
|
||||
x, y, 1.0);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user