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 2465 - Mac: Loss of mouse events after restoring window from thumbnail in Dock
Summary: Mac: Loss of mouse events after restoring window from thumbnail in Dock
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.3
Hardware: x86_64 Mac OS X 10.8
: P2 normal
Assignee: Jørgen Tjernø
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-26 15:26 UTC by John Knottenbelt
Modified: 2014-08-21 07:24 UTC (History)
2 users (show)

See Also:


Attachments
Patch (First fix). (1.28 KB, patch)
2014-03-26 16:06 UTC, John Knottenbelt
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Knottenbelt 2014-03-26 15:26:46 UTC
Steps to reproduce:
1. Minimise the window using the amber "-" icon at the top of the window frame.
2. Focus another application.
3. Restore the window by clicking on the thumbnail image of it in the Dock (*not* clicking on the Application Icon).
4. Notice that the window no longer receives left mouse down events reliably (you have to hit it several times, sometimes double clicking).

Investigation:

If the user restores the application by clicking on the Application icon in the Dock, it works correctly. The problem only occurs when the restoring from the thumbnail image of the window in the Dock, and also only if another application was focused while the window was minimized. The difference between these two ways of restoring the application is that:
  - When clicking on the Application icon, the application is made active first, and then the window is made visible (raised).
  - When clicking on the Window thumbnail, the window is made visible first and the application becomes active later.

The problem seems centre around calling [nswindow makeKeyAndOrderFront:nil] in Cocoa_RaiseWindow ( http://hg.libsdl.org/SDL/file/a31313cfa891/src/video/cocoa/SDL_cocoawindow.m#l1234 ) when the application is not active. This happens because the 'visible' observer is the first thing that triggers when restoring the application from the thumbnail in the dock. The application activation message happens somewhat later.

I notice also that once makeKeyAndOrderFront has been called while the application is inactive, the window does not in fact become key, and furthermore, even once the application becomes active later, calls to makeKeyAndOrderFront fail to make the window key.

I have identified two possible fixes. 

1. If the application is not active in Cocoa_RaiseWindow, just call [nswindow orderFront:nil] instead of [nswindow makeKeyAndOrderFront:nil].

2. Return early from observerValueForKeyPath if the application is not active: if (![NSApp isActive]) return;






Related to #1996
Comment 1 John Knottenbelt 2014-03-26 16:06:21 UTC
Created attachment 1598 [details]
Patch (First fix).

I've uploaded a patch for the first way of fixing it. If you want to see the patch for the second way please let me know.
Comment 2 Sam Lantinga 2014-04-18 05:53:48 UTC
Hey Jorgen, can you look and see if this approach is a good one?

Thanks!
Comment 3 (disabled) Jørgen Tjernø 2014-06-03 00:34:04 UTC
Unassigning as this account is no longer actively used.
Comment 4 Robotic-Brain 2014-08-18 02:12:55 UTC
I could not reproduce this on OSX 10.6. Has this been fixed along with https://bugzilla.libsdl.org/show_bug.cgi?id=1996 ?
Comment 5 John Knottenbelt 2014-08-19 16:11:58 UTC
I can confirm that the bug is still present as of Mac OS X 10.9.4 with SDL 2.0.3.

I have since updated from Mac OS X 10.8 which was the version I was running at the time I discovered the bug. Unfortunately, I don't have access to Mac OS X 10.6 to try it on.

Here is a youtube video of the bug running on Mac OS X 10.9.4 and SDL 2.0.3:

https://www.youtube.com/watch?v=QjbWJVs1ELM&feature=youtu.be

The demonstration program is an SDL tutorial by LazyFoo available at http://lazyfoo.net/tutorials/SDL/17_mouse_events/index.php . We've got an Xcode project file up at https://github.com/alimiv/SDLTest if you want to try building the code yourself.

In the video you can see that the bug manifests when the application is restored using the window thumbnail on the far right of the dock. The bug does not trigger if you use the application icon (on the left hand side of the dock).
Comment 6 Robotic-Brain 2014-08-19 16:46:58 UTC
Nope.. seems to be a OSX 10.7+ issue..
Comment 7 Alex Szpakowski 2014-08-20 05:08:28 UTC
John: have you tested with the latest SDL code from Mercurial?
Comment 8 John Knottenbelt 2014-08-20 11:17:05 UTC
Tested today and the bug does not reproduce with latest Mercurial (20 August 2014), so we can close this one down. 

For what it's worth, at the time of submitting the bug I did test with the latest Mercurial and the patch was against tip-of-tree (2014-03-26). Some patch between now and then must have coincidentally fixed this bug too. I wish I knew which one!
Comment 9 Sam Lantinga 2014-08-21 07:24:17 UTC
Glad to hear it, thanks!