简体   繁体   中英

How can I make a fullscreen overlay on the OS X desktop?

I want to make some kind of drawable surface that exists beneath the mouse cursor but above everything else rendered on the desktop. I am trying to create a "trail" behind the mouse.

How can I do this in Cocoa and Objective-C?

You need to subclass NSWindow to create a borderless window and set its window level to something like NSScreenSaverWindowLevel - 1 .

- (id)initWithContentRect:(NSRect)contentRect 
                styleMask:(NSUInteger)aStyle
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag
{
    self=[super initWithContentRect:contentRect 
                          styleMask:NSBorderlessWindowMask 
                            backing:bufferingType
                              defer:flag];

    if(self!=nil)
    {
        [self setHasShadow:NO];
        [self setOpaque:NO];
        [self setBackgroundColor:[NSColor clearColor]];
        [self setLevel:NSScreenSaverWindowLevel - 1];
    }
    return self;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM