Fixed divide by zero with a 1x1 sized window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c
index a4a5882..a602b2a 100644
--- a/src/video/x11/SDL_x11xinput2.c
+++ b/src/video/x11/SDL_x11xinput2.c
@@ -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;