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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With