Mouse coordinates in fullscreen
When my app is running windowed, I get mouse coordinates via NSWindow's mouseLocationOutsideOfEventStream. This works quite well. However, when I'm running fullscreen ( using code derived from OSC's GameShell ) this doesn't give me correct coordinates.
I do have an "emulated" mouse cursor mode, where I maintain the position of the mouse internally by monitoring mouse moved events and I draw my own cursor, and that works. But I'd prefer to use the "native" mouse cursor, since it's more responsive when my rendering load is too high. For an example of what I'm talking about, try playing the new Myst (5?) demo on a modest machine -- the mouse cursor is *unusable* because it's only updated as fast as the game can redraw the screen, and on my powerbook that's about 5 frames per second...
I've read over a lot of documentation, but I can't find anything like a global mouse position function that works without requiring a window as a reference point.
I do have an "emulated" mouse cursor mode, where I maintain the position of the mouse internally by monitoring mouse moved events and I draw my own cursor, and that works. But I'd prefer to use the "native" mouse cursor, since it's more responsive when my rendering load is too high. For an example of what I'm talking about, try playing the new Myst (5?) demo on a modest machine -- the mouse cursor is *unusable* because it's only updated as fast as the game can redraw the screen, and on my powerbook that's about 5 frames per second...
I've read over a lot of documentation, but I can't find anything like a global mouse position function that works without requiring a window as a reference point.
Worse, when you capture the screen and change resolution the Cocoa and Carbon frameworks aren't notified of the change, so they think the screen bounds are still what they were before the resolution switch.
If you don't mind calling private functions you can get the mouse position direct from CGS....
If you don't mind calling private functions you can get the mouse position direct from CGS....
You can call [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:true] to get events in a loop, and call [NSEvent mouseLocation] for the mouse location.
Again, that suffers from not knowing how big the screen is.
Exactly. I've already got an overridden NSApplication from which I extract and process events. I *know* when the mouse is moving, but when I'm in fullscreen, the coordinates are all wrong.
So, OSC, how about those undocumented functions...
So, OSC, how about those undocumented functions...
I use it without a problem. You can keep track of the screen dimensions yourself (since you need the size in order to change the resolution, anyway, or you can use a CG method to get the current display mode. (I don't remember the name offhand, I'll post it once I'm at my computer and can just look at the name in a project) If you change the resolution after the first time, you will need to offset the height by newHeight - oldHeight + 1. I use this method myself, and it works perfectly.
Edit: what I mean by first time is, when I reset the resolution before just about everything else, it gets the correct coordinates. Afterwards, all I have to do is change the y offset, and everything works perfectly.
Edit: what I mean by first time is, when I reset the resolution before just about everything else, it gets the correct coordinates. Afterwards, all I have to do is change the y offset, and everything works perfectly.
That seems way too brittle to me. It may very well work now, but it seems like a minor change in the behavior of the window server could break it.
Come on, there's *got* to be a way to find the mouse position on screen...
Come on, there's *got* to be a way to find the mouse position on screen...
I spent several hours helping someone troubleshoot this same issue, and the solution akb825 suggested was the best we could find. I suppose your worry about using it is that future OS versions will behave differently?
- Alex Diener
- Alex Diener
Yeah, basically I have to assume an origin point for the fullscreen and use the offset from there to the windowed view to "correct" my mouse coordinates. Seems pretty crummy to me, because any old change in the window server could change where the offset is. Or if the menu bar changes sizes ( which *could* happen, when resulution independance happens ) or any other number of factors.
If I have to rely on a hack, then, I will not do it at all. My emulated mouse works fine... it's just non-optimal.
If I have to rely on a hack, then, I will not do it at all. My emulated mouse works fine... it's just non-optimal.
...any other number of factors, like the user having three displays in arbitrary relative locations.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| openal coordinates vs. opengl coordinates | gerald | 1 | 5,418 |
Feb 3, 2011 10:04 PM Last Post: OneSadCookie |
|
| Tip: Fullscreen mouse event gotcha | Fenris | 3 | 2,815 |
Feb 13, 2006 07:41 PM Last Post: AnotherJake |
|
| SDL mouse event coordinates | MattDiamond | 9 | 11,372 |
Oct 3, 2005 06:38 PM Last Post: PowerMacX |
|
| Mouse Position In Fullscreen... | thaeez | 6 | 3,964 |
Nov 5, 2004 02:38 PM Last Post: thaeez |
|
| How to get mouse events in fullscreen AGL? | DoG | 7 | 4,457 |
Oct 9, 2003 01:01 PM Last Post: FCCovett |
|

