开发者

NSTrackingArea with fullscreen window/view

开发者 https://www.devze.com 2022-12-19 04:37 出处:网络
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 f

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:[WLMac开发者_开发百科GLView 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号