Skip to content

Commit

Permalink
Fixed divide by zero with a 1x1 sized window
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 12, 2017
1 parent bef0fec commit 5bed4ca
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/video/x11/SDL_x11xinput2.c
Expand Up @@ -74,23 +74,34 @@ 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)
{
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;
int i;
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;
}
}
// couldn't find the window...
*out_x = in_x;
*out_y = in_y;
}
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */

#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */

void
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 5bed4ca

Please sign in to comment.