From 9306ef9b10a62b7843e7e38ba4244c36607dffcf Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 16 Jun 2019 14:10:30 -0300 Subject: [PATCH] Fix synthetically generated mouse events getting lost forever after the device orientation changes (or the window is otherwise resized) while a finger is touching the screen. --- src/events/SDL_touch.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index e70214d16..ff2d70618 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -262,6 +262,15 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, /* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */ if (id != SDL_MOUSE_TOUCHID) { SDL_Window *window = SDL_GetMouseFocus(); + if (window == NULL) { + /* Mouse focus may have been lost by e.g. the window resizing + * due to device orientation change while the mouse state is + * pressed (because its position is now out of the window). + * SendMouse* will update mouse focus again after that, but + * if those are never called then SDL might think the + * 'mouse' has no focus at all. */ + window = SDL_GetKeyboardFocus(); + } if (window) { if (down) { if (finger_touching == SDL_FALSE) {