diff -r ac809ea54d63 src/video/x11/SDL_x11xinput2.c --- a/src/video/x11/SDL_x11xinput2.c Mon Dec 16 10:03:26 2013 -0300 +++ b/src/video/x11/SDL_x11xinput2.c Mon Dec 16 21:24:38 2013 +0100 @@ -125,9 +125,39 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie) { #if SDL_VIDEO_DRIVER_X11_XINPUT2 + +#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH + double window_w = 1.0; + double window_h = 1.0; +#endif + if(cookie->extension != xinput2_opcode) { return 0; } + +#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH + /* Get Width and Heigh of the Window the event belongs to. + * Then, normalize the position (event_x, event_y). + * Notice that the event may belong to a Window and be outside of it. + * If so, the normalized coordinates are <0 or >1. + * (0, 0) is the upper left corner of the window. + */ + if (cookie->evtype == XI_TouchBegin || cookie->evtype == XI_TouchEnd || cookie->evtype == XI_TouchUpdate) { + const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; + int i = 0; + + for (i = 0; i < videodata->numwindows; i++) { + const SDL_WindowData *window_data = videodata->windowlist[i]; + + if (window_data->xwindow == xev->event) { + window_w = window_data->window->w; + window_h = window_data->window->h; + break; + } + } + } +#endif + switch(cookie->evtype) { case XI_RawMotion: { const XIRawEvent *rawev = (const XIRawEvent*)cookie->data; @@ -148,21 +178,21 @@ case XI_TouchBegin: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; SDL_SendTouch(xev->sourceid,xev->detail, - SDL_TRUE, xev->event_x, xev->event_y, 1.0); + SDL_TRUE, xev->event_x / window_w, xev->event_y / window_h, 1.0); return 1; } break; case XI_TouchEnd: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; SDL_SendTouch(xev->sourceid,xev->detail, - SDL_FALSE, xev->event_x, xev->event_y, 1.0); + SDL_FALSE, xev->event_x / window_w, xev->event_y / window_h, 1.0); return 1; } break; case XI_TouchUpdate: { const XIDeviceEvent *xev = (const XIDeviceEvent *) cookie->data; SDL_SendTouchMotion(xev->sourceid,xev->detail, - xev->event_x, xev->event_y, 1.0); + xev->event_x / window_w, xev->event_y / window_h, 1.0); return 1; } break;