src/video/x11/SDL_x11xinput2.c
changeset 11602 8dd72342f1f1
parent 11598 6fde74294cc9
child 11811 5d94cb6b24d3
     1.1 --- a/src/video/x11/SDL_x11xinput2.c	Thu Oct 12 14:28:05 2017 +0300
     1.2 +++ b/src/video/x11/SDL_x11xinput2.c	Thu Oct 12 08:27:22 2017 -0700
     1.3 @@ -74,23 +74,34 @@
     1.4      return ( version >= ((wantmajor * 1000) + wantminor) );
     1.5  }
     1.6  
     1.7 +#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
     1.8  static void
     1.9  xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
    1.10      double in_x, double in_y, float *out_x, float *out_y)
    1.11  {
    1.12 -   int i;
    1.13 -   for (i = 0; i < videodata->numwindows; i++) {
    1.14 -      SDL_WindowData *d = videodata->windowlist[i];
    1.15 -      if (d->xwindow == window) {
    1.16 -         *out_x = in_x / (d->window->w-1);
    1.17 -         *out_y = in_y / (d->window->h-1);
    1.18 -         return;
    1.19 -      }
    1.20 -   }
    1.21 -   // couldn't find the window...
    1.22 -   *out_x = in_x;
    1.23 -   *out_y = in_y;
    1.24 +    int i;
    1.25 +    for (i = 0; i < videodata->numwindows; i++) {
    1.26 +        SDL_WindowData *d = videodata->windowlist[i];
    1.27 +        if (d->xwindow == window) {
    1.28 +            if (d->window->w == 1) {
    1.29 +                *out_x = 0.5f;
    1.30 +            } else {
    1.31 +                *out_x = in_x / (d->window->w - 1);
    1.32 +            }
    1.33 +            if (d->window->h == 1) {
    1.34 +                *out_y = 0.5f;
    1.35 +            } else {
    1.36 +                *out_y = in_y / (d->window->h - 1);
    1.37 +            }
    1.38 +            return;
    1.39 +        }
    1.40 +    }
    1.41 +    // couldn't find the window...
    1.42 +    *out_x = in_x;
    1.43 +    *out_y = in_y;
    1.44  }
    1.45 +#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
    1.46 +
    1.47  #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    1.48  
    1.49  void
    1.50 @@ -192,8 +203,7 @@
    1.51              float x, y;
    1.52              xinput2_normalize_touch_coordinates(videodata, xev->event,
    1.53                                    xev->event_x, xev->event_y, &x, &y);
    1.54 -            SDL_SendTouch(xev->sourceid,xev->detail,
    1.55 -                      SDL_TRUE, x, y, 1.0);
    1.56 +            SDL_SendTouch(xev->sourceid,xev->detail, SDL_TRUE, x, y, 1.0);
    1.57              return 1;
    1.58              }
    1.59              break;
    1.60 @@ -202,8 +212,7 @@
    1.61              float x, y;
    1.62              xinput2_normalize_touch_coordinates(videodata, xev->event,
    1.63                                    xev->event_x, xev->event_y, &x, &y);
    1.64 -            SDL_SendTouch(xev->sourceid,xev->detail,
    1.65 -                      SDL_FALSE, x, y, 1.0);
    1.66 +            SDL_SendTouch(xev->sourceid,xev->detail, SDL_FALSE, x, y, 1.0);
    1.67              return 1;
    1.68              }
    1.69              break;
    1.70 @@ -212,8 +221,7 @@
    1.71              float x, y;
    1.72              xinput2_normalize_touch_coordinates(videodata, xev->event,
    1.73                                    xev->event_x, xev->event_y, &x, &y);
    1.74 -            SDL_SendTouchMotion(xev->sourceid,xev->detail,
    1.75 -                                x, y, 1.0);
    1.76 +            SDL_SendTouchMotion(xev->sourceid,xev->detail, x, y, 1.0);
    1.77              return 1;
    1.78              }
    1.79              break;