src/video/x11/SDL_x11xinput2.c
changeset 11598 6fde74294cc9
parent 10737 3406a0f8b041
child 11602 8dd72342f1f1
equal deleted inserted replaced
11597:7ee20a756f96 11598:6fde74294cc9
    70 
    70 
    71 static SDL_bool
    71 static SDL_bool
    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 }
       
    76 
       
    77 static void
       
    78 xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
       
    79     double in_x, double in_y, float *out_x, float *out_y)
       
    80 {
       
    81    int i;
       
    82    for (i = 0; i < videodata->numwindows; i++) {
       
    83       SDL_WindowData *d = videodata->windowlist[i];
       
    84       if (d->xwindow == window) {
       
    85          *out_x = in_x / (d->window->w-1);
       
    86          *out_y = in_y / (d->window->h-1);
       
    87          return;
       
    88       }
       
    89    }
       
    90    // couldn't find the window...
       
    91    *out_x = in_x;
       
    92    *out_y = in_y;
    75 }
    93 }
    76 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    94 #endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
    77 
    95 
    78 void
    96 void
    79 X11_InitXinput2(_THIS)
    97 X11_InitXinput2(_THIS)
   169             break;
   187             break;
   170 
   188 
   171 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
   189 #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
   172         case XI_TouchBegin: {
   190         case XI_TouchBegin: {
   173             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   191             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
       
   192             float x, y;
       
   193             xinput2_normalize_touch_coordinates(videodata, xev->event,
       
   194                                   xev->event_x, xev->event_y, &x, &y);
   174             SDL_SendTouch(xev->sourceid,xev->detail,
   195             SDL_SendTouch(xev->sourceid,xev->detail,
   175                       SDL_TRUE, xev->event_x, xev->event_y, 1.0);
   196                       SDL_TRUE, x, y, 1.0);
   176             return 1;
   197             return 1;
   177             }
   198             }
   178             break;
   199             break;
   179         case XI_TouchEnd: {
   200         case XI_TouchEnd: {
   180             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   201             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
       
   202             float x, y;
       
   203             xinput2_normalize_touch_coordinates(videodata, xev->event,
       
   204                                   xev->event_x, xev->event_y, &x, &y);
   181             SDL_SendTouch(xev->sourceid,xev->detail,
   205             SDL_SendTouch(xev->sourceid,xev->detail,
   182                       SDL_FALSE, xev->event_x, xev->event_y, 1.0);
   206                       SDL_FALSE, x, y, 1.0);
   183             return 1;
   207             return 1;
   184             }
   208             }
   185             break;
   209             break;
   186         case XI_TouchUpdate: {
   210         case XI_TouchUpdate: {
   187             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
   211             const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data;
       
   212             float x, y;
       
   213             xinput2_normalize_touch_coordinates(videodata, xev->event,
       
   214                                   xev->event_x, xev->event_y, &x, &y);
   188             SDL_SendTouchMotion(xev->sourceid,xev->detail,
   215             SDL_SendTouchMotion(xev->sourceid,xev->detail,
   189                                 xev->event_x, xev->event_y, 1.0);
   216                                 x, y, 1.0);
   190             return 1;
   217             return 1;
   191             }
   218             }
   192             break;
   219             break;
   193 #endif
   220 #endif
   194     }
   221     }