Mouse coordinates in fullscreen

Sage
Posts: 1,199
Joined: 2004.10
Post: #1
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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....
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #3
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Again, that suffers from not knowing how big the screen is.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #5
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... Sneaky
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #6
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.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
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...
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #8
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
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #9
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
...any other number of factors, like the user having three displays in arbitrary relative locations.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  openal coordinates vs. opengl coordinates gerald 1 6,013 Feb 3, 2011 10:04 PM
Last Post: OneSadCookie
  Tip: Fullscreen mouse event gotcha Fenris 3 3,070 Feb 13, 2006 07:41 PM
Last Post: AnotherJake
  SDL mouse event coordinates MattDiamond 9 13,129 Oct 3, 2005 06:38 PM
Last Post: PowerMacX
  Mouse Position In Fullscreen... thaeez 6 4,284 Nov 5, 2004 02:38 PM
Last Post: thaeez
  How to get mouse events in fullscreen AGL? DoG 7 5,800 Oct 9, 2003 01:01 PM
Last Post: FCCovett