Unsacrificed
Unsacrificed

Reputation: 189

Mac OS low-level window framework

Currently I use AppKit's NSWindow to create windows. The problem is that it has a lot of "default behaviour"/limitations. For example: miniaturize does not work if there is no titlebar (also I have some troubles with borderless window, with corner radius and etc.).

I understand that this "default behaviour" is good in most cases, but not in my.

Is there any low-level window API (C/C++/Obj-C) for Mac OS? I don't need any Views, controls and etc. All I need - area to draw and source of events.

Upvotes: 3

Views: 326

Answers (1)

Guilherme Rambo
Guilherme Rambo

Reputation: 2046

You can still use NSWindow and implement your custom behavior on top of it. The best way to achieve that would be to create your own subclass of NSWindow and override the behaviors you want. This sample code creates a NSWindow which has no titlebar, has rounded corners and can be miniaturized:

@interface CustomWindow : NSWindow

@end

@implementation CustomWindow

- (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag
{
    NSWindowStyleMask effectiveStyle = style | NSWindowStyleMaskFullSizeContentView;
    self = [super initWithContentRect:contentRect styleMask:effectiveStyle backing:backingStoreType defer:NO];

    self.titleVisibility = NSWindowTitleHidden;
    self.titlebarAppearsTransparent = YES;

    self.movableByWindowBackground = YES;

    [self standardWindowButton:NSWindowCloseButton].hidden = YES;
    [self standardWindowButton:NSWindowZoomButton].hidden = YES;
    [self standardWindowButton:NSWindowMiniaturizeButton].hidden = YES;

    return self;
}

Upvotes: 2

Related Questions