Fixed divide by zero with a 1x1 sized window
parent
bef0fec121
commit
5bed4ca92e
|
@ -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
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue