i crate a fully transparent NSWindow like this:
NSWindowStyleMask styleMask = NSBorderlessWindowMask | NSFullSizeContentViewWindowMask;
NSWinod *window = [[BrowserNSWindow alloc] initWithContentRect:NSMakeRect(0,0,500,600)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
[window setBackgroundColor:[NSColor clearColor]];
[window setOpaque:NO];
[window setHasShadow:NO];
NSCustomView *view = [[NSCustomView alloc] initWithFrame:NSMakeRect(0,0,500,600)];
[view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[view setAutoresizesSubviews: true];
[window.contentView addSubview:view];
and override the NSView drawRect function:
- (void)drawRect:(NSRect)rect
{
[[NSColor clearColor] set];
NSRectFill(rect);
NSRectFillUsingOperation(rect, NSCompositingOperationSourceOver);
}
i call setNeedDisplay:YES to redraw the view. in macos sonoma, i found that when after multiple calls setNeedDisplay:YES, the transparent window can't click through. This feature run correctly in previous versions, like macos 13
This might have something to do with the fact that the
clipsToBoundsproperty of NSViews are no longer set to true by default in Sonoma, so therectpassed to thedrawRect:method might extend outside the view bounds.Try either explicitly setting
or clipping the rect to the view bounds in
drawRect: