agg23
agg23

Reputation: 81

Outlining a System Window

I'm trying to outline a window similarly to Mission Control and Exposé. I've created a custom NSWindow that is transparent and has an outline similar to this question, but I don't want the user to interact with this window at all.

Is there any way to do this?

Below is my custom NSWindow, which I've been calling with

windowOutline = [[WindowOutline alloc] initWithContentRect:rect styleMask:1 backing:NSBackingStoreBuffered defer:false];
    [windowOutline makeKeyAndOrderFront:self];
    [windowOutline drawRect:rect];

- (id)initWithContentRect:(NSRect)contentRect
                styleMask:(NSUInteger)windowStyle
                  backing:(NSBackingStoreType)bufferingType
                    defer:(BOOL)flag
{
    self = [super
            initWithContentRect:contentRect
            styleMask:NSBorderlessWindowMask
            backing:bufferingType
            defer:flag];
    if (self)
    {
        [self setOpaque:NO];
        [self setBackgroundColor:[NSColor clearColor]];
    }
    return self;
}

- (void)drawRect:(NSRect)frame {
    frame = NSInsetRect(self.frame, 3.0, 3.0);

    [NSBezierPath setDefaultLineWidth:6.0];

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame
                                                         xRadius:6.0 yRadius:6.0];
    [[NSColor redColor] set];
    [path stroke];
}

Upvotes: 0

Views: 108

Answers (1)

puzzle
puzzle

Reputation: 6131

You're already half way there. You need to create a custom window and content view as described in the answer you've already found. Note that drawRect: is in the custom view (which you'll set as your window's contentView), not in your window subclass. From your code snippet it's not entirely clear if you have set it up that way. You should now have a transparent, outlined window.

You'll then need to:

  1. Set the window level -[NSWindow setLevel:] one of the constants above NSNormalWindowLevel.
  2. Make your application an agent app so it doesn't appear in the Dock etc. by setting LSUIElement in the Info.plist.
  3. Set ignoresMouseEvents on the window to YES.

Upvotes: 1

Related Questions