views:

140

answers:

2

I'm trying to install a NSTrackingArea into a fullscreen view in order to get mouse moved events.

However, whenever I do, I get an assertion error. I've searched the web, but have not been able to find any leads.

*** Assertion failure in -[_NSFullScreenWindow _setTrackingRect:inside:owner:userData:useTrackingNum:install:], /SourceCache/AppKit/AppKit-1038.25/AppKit.subproj/NSWindow.m:3944

Here's the code that sets up the tracking area (x=1024, y=768):

    cocoaWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, x,y)
                                              styleMask: NSTitledWindowMask
                                                backing: NSBackingStoreBuffered
                                                  defer:NO];
    glView = [[WLMacGLView alloc] initWithFrame:NSMakeRect(0.0, 0.0,  x,y) pixelFormat:[WLMacGLView defaultPixelFormat]];
    [glView setCocoaController:self];

    //add the glView as a subview of the window's content view
    [[cocoaWindow contentView] addSubview:glView];
    NSRect r = [glView frame];
    NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:r options: NSTrackingMouseMoved | NSTrackingActiveWhenFirstResponder | NSTrackingActiveInKeyWindow
                                   owner:self userInfo:nil];
    [glView addTrackingArea:track];
    [glView enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
    [glView createContext];

The assertion happens right after the call to enterFullScreenMode: withOptions:

Anyone got any ideas? Is this not the approach I should be taking to get mouse moved events in a fullscreen window?

A: 

If you want to track mouse in the whole view, I think is will be easier to implement the mouseDown:, mouseMoved: and mouseUp: methods in order to get the mouse events.

Laurent Etiemble
Those methods are implemented, but they don't get called when the window is fullscreen.
Wade Williams
There is sample application that you can take a look at: http://developer.apple.com/mac/library/samplecode/GeekGameBoard/index.html (it uses a NSView subclass not an OpenGL one).
Laurent Etiemble
Make sure you call `[[glView window] setAcceptsMouseMovedEvents:YES]` if you want to use `-mouseMoved:`.
Rob Keniger
A: 

So the answer to this question turned out to be a bug in my own code.

When initializing the NSTrackingArea, I was passing in the wrong object for owner. The proper thing to pass was the NSView. With that corrected, all works as expected.

Wade Williams