src/video/x11/SDL_x11xinput2.c
changeset 11602 8dd72342f1f1
parent 11598 6fde74294cc9
child 11811 5d94cb6b24d3
equal deleted inserted replaced
11601:22fe56a64c6f 11602:8dd72342f1f1
    72 xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
    72 xinput2_version_atleast(const int version, const int wantmajor, const int wantminor)
    73 {
    73 {
    74     return ( version >= ((wantmajor * 1000) + wantminor) );
    74     return ( version >= ((wantmajor * 1000) + wantminor) );
    75 }
    75 }
    76 
    76 
       
    77 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
    77 static void
    78 static void
    78 xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
    79 xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
    79     double in_x, double in_y, float *out_x, float *out_y)
    80     double in_x, double in_y, float *out_x, float *out_y)
    80 {
    81 {
    81    int i;
    82     int i;
    82    for (i = 0; i < videodata->numwindows; i++) {
    83     for (i = 0; i < videodata->numwindows; i++) {
    83       SDL_WindowData *d = videodata->windowlist[i];
    84         SDL_WindowData *d = videodata->windowlist[i];
    84       if (d->xwindow == window) {
    85         if (d->xwindow == window) {
    85          *out_x = in_x / (d->window->w-1);
    86             if (d->window->w == 1) {
    86          *out_y = in_y / (d->window->h-1);
    87                 *out_x = 0.5f;
    87          return;
    88             } else {
    88       }
    89                 *out_x = in_x / (d->window->w - 1);
    89    }
    90             }
    90    // couldn't find the window...
    91             if (d->window->h == 1) {
    91    *out_x = in_x;
    92                 *out_y = 0.5f;
    92    *out_y = in_y;
    93             } else {
    93 }
    94                 *out_y = in_y / (d->window->h - 1);
       
    95             }
       
    96             return;
       
    97         }
       
    98     }
       
    99     // couldn't find the window...
       
   100     *out_x = in_x;
       
   101     *out_y = in_y;
       
   102 }
       
   103 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
       
   104 
    94 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
   105 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    95 
   106 
    96 void
   107 void
    97 X11_InitXinput2(_THIS)
   108 X11_InitXinput2(_THIS)
    98 {
   109 {
   190         case XI_TouchBegin: {
   201         case XI_TouchBegin: {
   191             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   202             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   192             float x, y;
   203             float x, y;
   193             xinput2_normalize_touch_coordinates(videodata, xev->event,
   204             xinput2_normalize_touch_coordinates(videodata, xev->event,
   194                                   xev->event_x, xev->event_y, &x, &y);
   205                                   xev->event_x, xev->event_y, &x, &y);
   195             SDL_SendTouch(xev->sourceid,xev->detail,
   206             SDL_SendTouch(xev->sourceid,xev->detail, SDL_TRUE, x, y, 1.0);
   196                       SDL_TRUE, x, y, 1.0);
       
   197             return 1;
   207             return 1;
   198             }
   208             }
   199             break;
   209             break;
   200         case XI_TouchEnd: {
   210         case XI_TouchEnd: {
   201             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   211             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   202             float x, y;
   212             float x, y;
   203             xinput2_normalize_touch_coordinates(videodata, xev->event,
   213             xinput2_normalize_touch_coordinates(videodata, xev->event,
   204                                   xev->event_x, xev->event_y, &x, &y);
   214                                   xev->event_x, xev->event_y, &x, &y);
   205             SDL_SendTouch(xev->sourceid,xev->detail,
   215             SDL_SendTouch(xev->sourceid,xev->detail, SDL_FALSE, x, y, 1.0);
   206                       SDL_FALSE, x, y, 1.0);
       
   207             return 1;
   216             return 1;
   208             }
   217             }
   209             break;
   218             break;
   210         case XI_TouchUpdate: {
   219         case XI_TouchUpdate: {
   211             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   220             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   212             float x, y;
   221             float x, y;
   213             xinput2_normalize_touch_coordinates(videodata, xev->event,
   222             xinput2_normalize_touch_coordinates(videodata, xev->event,
   214                                   xev->event_x, xev->event_y, &x, &y);
   223                                   xev->event_x, xev->event_y, &x, &y);
   215             SDL_SendTouchMotion(xev->sourceid,xev->detail,
   224             SDL_SendTouchMotion(xev->sourceid,xev->detail, x, y, 1.0);
   216                                 x, y, 1.0);
       
   217             return 1;
   225             return 1;
   218             }
   226             }
   219             break;
   227             break;
   220 #endif
   228 #endif
   221     }
   229     }