From cfefe5434a119d788a165eb5d749e38b2a9a280f Mon Sep 17 00:00:00 2001 From: Sylvain Becker Date: Mon, 8 Apr 2019 21:27:24 +0200 Subject: [PATCH] Fixed bug 4581 - mouse events with SDL_TOUCH_MOUSEID make window lost focus Virtual mouse events should never leave the window or change focus for single window applications. --- src/events/SDL_touch.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 2c5375fd8..a5278d4e7 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -257,12 +257,18 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, if (finger_touching == SDL_FALSE) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); - SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); + if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { + SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT); + } } } else { if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) { - SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); + int pos_x = (int)(x * (float)window->w); + int pos_y = (int)(y * (float)window->h); + if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { + SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT); + } } } } @@ -355,7 +361,9 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) { int pos_x = (int)(x * (float)window->w); int pos_y = (int)(y * (float)window->h); - SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + if (pos_x >= 0 && pos_y >= 0 && pos_x < window->w && pos_y < window->h) { + SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y); + } } } }