LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: wtfwtf_ok on February 25, 2011, 22:21:52

Title: [FIXED] Mac: focusing mouse click has incorrect coordinates
Post by: wtfwtf_ok on February 25, 2011, 22:21:52
This post discusses a scatter of problems: http://lwjgl.org/forum/index.php?topic=3413.0

But I would like to discuss only one of them.

Clicking a window to focus it passes the click through, but the mouse coordinates are incorrect (they will be the same coordinates as the last mouse event received prior to the window losing focus). This is really annoying.

If the mouse coordinates cannot be correct, I would rather the focusing click be suppressed. Better yet, the coordinates can be fixed and there would be an API method to determine if the click was the click used to focus the window, and we could decide whether to drop the click or use it. (Some native Mac apps do one, some do the other).
Title: Re: [BUG] Mac: focusing mouse click has incorrect coordinates
Post by: kappa on February 26, 2011, 14:02:41
this is an issue with apple's implementation of java where unfocused AWT Windows/Frames don't get MouseMoved events.

If anyone is aware of some workaround for this feel free to point it out.

I'll have a look to see if there is anything we can do on the LWJGL side to fix this.
Title: Re: [BUG] Mac: focusing mouse click has incorrect coordinates
Post by: kappa on February 26, 2011, 14:34:31
ok looks like I found the answer here (http://lists.apple.com/archives/java-dev/2010/Jul/msg00140.html). The default behaviour of Cocoa app's (AWT is implemented in Cocoa on mac) is that by default they don't report MouseMoved events on unfocused windows and you have to explicitly turn it on. For whatever reason Apple's AWT implementation doesn't have this switch on by default.

The solution is simple (pointed out in the above link) you just have to call [NSWindow setAcceptsMouseMovedEvents:YES] in native code to switch it on. Not sure whether we should switch it on in LWJGL or file a RFE on Apple's bug reporter.

I'll have a go at this tonight and if it works reasonably well, will make a patch.
Title: Re: [BUG] Mac: focusing mouse click has incorrect coordinates
Post by: kappa on February 26, 2011, 20:55:55
I've attempted to fix this today but seems that [NSWindow setAcceptsMouseMovedEvents:YES] isn't going to be enough to fix this.

It seems that Cocoa app's in general can't get MouseMoved Events if the window isn't focused.

Apple did however address this problem by adding a new api called NSTrackingArea. This allows one to get MouseMovedEvents on non focused windows. The problem though is that NSTrackingArea requires OS X 10.5+ but can be added in a backward compatible way (i.e. won't do anything on OS X 10.3 and 10.4).

Need to spend more time to integrate NSTrackingArea into the code so will probably look into it later, hopefully sometime before LWJGL's 2.8 release but in the meantime ppl are free to also look into the problem and submit patches :).
Title: Re: [BUG] Mac: focusing mouse click has incorrect coordinates
Post by: kappa on November 01, 2013, 11:19:28
This issue is fixed in LWJGL 2.9