mouse location woes

Member
Posts: 469
Joined: 2002.10
Post: #1
In Cocoa I used
Code:
newMode = CGDisplayBestModeForParameters(kCGDirectMainDisplay, 24, width, height, 0);
CGDisplaySwitchToMode(kCGDirectMainDisplay, newMode);
to change to a full screen context.

How do I get the mouse location on the screen?
When I do:
Code:
NSPoint mouseLoc = [NSEvent mouseLocation];
I get a Point that is x pixels too high, where x is the old screen height - the new screen height + 1. (289 in my case 768-480+1)

Does anyone know a fix or another way to get the mouse location?
(I don't have a nsview or nswindow btw, as I am drawing direct to the screen.)

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 201
Joined: 2002.06
Post: #2
I don't know what the problem is with the way you're doing it, but, just in case this may work for your purposes, this returns the mouse position change associated with the last mouse move event received by this application.

Code:
void CGGetLastMouseDelta(
    CGMouseDelta * deltaX,
    CGMouseDelta * deltaY );
Quote this message in a reply
blb
Unregistered
 
Post: #3
I'd love to find a cleaner way than:
Code:
NSPoint mouseLoc;
Point carbonPoint;

GetMouse( &carbonPoint );
mouseLoc.x = carbonPoint.h;
mouseLoc.y = [ self bounds ].size.height - carbonPoint.v;
but when in full screen, this is the best I've found. Of course, if you just need deltas, geezusfreeek's method is the way to go.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
I seem to recall that there's a bug in the communication between CGDirectDisplay and NSScreen. I think there's a (hack) fix which involves playing directly with NSScreen's internals.

Personally, if I was already using CG for full-screen, I'd probably be tempted to use CG to get the mouse movement, as others have suggested. Just store the mouse's current position, and manually update it by calling CGGetLastMouseDelta or whatever it's called when you receive a mouse moved event.
Quote this message in a reply
wally
Unregistered
 
Post: #5
Quote:Originally posted by OneSadCookie
I seem to recall that there's a bug in the communication between CGDirectDisplay and NSScreen. I think there's a (hack) fix which involves playing directly with NSScreen's internals.

And here's the hack (from SDL)
Code:
/*
    Add methods to get at private members of NSScreen.
    Since there is a bug in Apple's screen switching code
    that does not update this variable when switching
    to fullscreen, we'll set it manually (but only for the
    main screen).
*/
@interface NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
@end

@implementation NSScreen (NSScreenAccess)
- (void) setFrame:(NSRect)frame;
{
    _frame = frame;
}
@end
Now, when you set the new resolution, use this:
Code:
NSRect screen_rect = NSMakeRect(0,0,width,height);
[ [ NSScreen mainScreen ] setFrame:screen_rect ];
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ending location from angle and speed Kazooless 5 4,629 Apr 3, 2009 02:40 PM
Last Post: Gillissie
  polling mouse location? alloca 1 2,545 Jan 22, 2009 04:14 PM
Last Post: ThemsAllTook
  Cocoa: Mouse location while dragging window Fenris 4 5,139 Jul 14, 2005 04:46 PM
Last Post: Fenris
  Getting mouse location Steven 25 8,200 Aug 3, 2003 07:24 PM
Last Post: OneSadCookie
  Setting the mouse location Michael 6 4,286 Jun 22, 2003 03:39 AM
Last Post: reubert