We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3121 - Once mouse focus is lost, it is not regainable anymore.
Summary: Once mouse focus is lost, it is not regainable anymore.
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.3
Hardware: All Android (All)
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-14 11:05 UTC by Daniel Brall
Modified: 2015-09-15 06:31 UTC (History)
1 user (show)

See Also:


Attachments
Suggested solution (1.98 KB, patch)
2015-09-14 11:05 UTC, Daniel Brall
Details | Diff
Logfile with window and mouse events. (7.60 KB, text/plain)
2015-09-14 12:23 UTC, Daniel Brall
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Brall 2015-09-14 11:05:39 UTC
Created attachment 2265 [details]
Suggested solution

-------------
Situation
-------------

1. Game with UnityAds SDK for showing advertisment.
2. Fullscreen Advertising Activity appears on Mouse-Up SDL event.
3. Then you click around on the advertisment (skip it) and even change the orientation of the screen.
4. Afterwards you close it by pressing the (X) at the top right corner.


-------------
Result
-------------

Further mouse events after these 4 steps won't have valid coordinates due to the fact that the mouse focus got lost and is never retrievable anymore.


-------------
Reasoning
-------------

The problem is that mouse->focus got NULL due to the screen resizing or orientation changes and touch events which occurred while closing the ad activity. It seems that the coordinates of a touch event have been outside the window and the focus has been set to NULL.


-------------
Solution
-------------

I wouldn't like to change something non-platform-dependent. That's why I changed SDL_androidtouch.c and not something more general. The main problem was that the coordinates are for a short time outside the window dimensions. I looked at the code and I've noticed something even more suspect:

In the function Android_OnTouch it translates floating point touch coordinates to window coordinates to convert them to mouse events. Therefore it uses the global reference to Android_Window. Afterwards it tries to send the events via SDL_SendMouseMotion/SDL_SendMouseButton to a NULL window, but why? We're already using Android_Window to get the coordinates for this specific window, why shouldn't we send the events to Android_Window then, too?

This would also allow us to regain the focus, after a partial unintended touch event messed it up.

See my patch in the attachments.

Btw. as help for your own search:
The only SDL_SetMouseFocus(NULL) occurrence which is available on android is inside SDL_UpdateMouseFocus. SDL_UpdateMouseFocus itself is only available in SDL_SendMouseMotion (1x) and SDL_SendMouseButton (2x). And they are called from SDL_androidtouch.c.
Comment 1 Daniel Brall 2015-09-14 12:23:51 UTC
Created attachment 2266 [details]
Logfile with window and mouse events.
Comment 2 Philipp Wiesemann 2015-09-14 19:19:02 UTC
If this patch fixes the problem then it was already fixed with bug 2611 (where an identical patch was applied).
Comment 3 Daniel Brall 2015-09-15 06:31:41 UTC
(In reply to Philipp Wiesemann from comment #2)
> If this patch fixes the problem then it was already fixed with bug 2611
> (where an identical patch was applied).

Thanks for the information, yes it is fixing it.