Fixed divide by zero with a 1x1 sized window

This commit is contained in:
Sam Lantinga 2017-10-12 08:27:22 -07:00
parent bef0fec121
commit 5bed4ca92e

View File

@ -74,6 +74,7 @@ xinput2_version_atleast(const int version, const int wantmajor, const int wantmi
return ( version >= ((wantmajor * 1000) + wantminor) );
}
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
static void
xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
double in_x, double in_y, float *out_x, float *out_y)
@ -82,8 +83,16 @@ xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
for (i = 0; i < videodata->numwindows; i++) {
SDL_WindowData *d = videodata->windowlist[i];
if (d->xwindow == window) {
if (d->window->w == 1) {
*out_x = 0.5f;
} else {
*out_x = in_x / (d->window->w - 1);
}
if (d->window->h == 1) {
*out_y = 0.5f;
} else {
*out_y = in_y / (d->window->h - 1);
}
return;
}
}
@ -91,6 +100,8 @@ xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
*out_x = in_x;
*out_y = in_y;
}
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
void
@ -192,8 +203,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
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, x, y, 1.0);
SDL_SendTouch(xev->sourceid,xev->detail, SDL_TRUE, x, y, 1.0);
return 1;
}
break;
@ -202,8 +212,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
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, x, y, 1.0);
SDL_SendTouch(xev->sourceid,xev->detail, SDL_FALSE, x, y, 1.0);
return 1;
}
break;
@ -212,8 +221,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
float x, y;
xinput2_normalize_touch_coordinates(videodata, xev->event,
xev->event_x, xev->event_y, &x, &y);
SDL_SendTouchMotion(xev->sourceid,xev->detail,
x, y, 1.0);
SDL_SendTouchMotion(xev->sourceid,xev->detail, x, y, 1.0);
return 1;
}
break;