diff --git a/examples/window_example/main.cpp b/examples/window_example/main.cpp index 5d0b929..bcf81e4 100644 --- a/examples/window_example/main.cpp +++ b/examples/window_example/main.cpp @@ -35,6 +35,7 @@ int main() { // Create a new window (automatically registered) std::shared_ptr window_ptr = std::make_shared(); window_ptr->SetTitle("Window Example"); + window_ptr->SetTitleBarStyle(nativeapi::TitleBarStyle::Hidden); window_ptr->SetSize({800, 600}, false); window_ptr->SetMinimumSize({400, 300}); window_ptr->SetMaximumSize({1920, 1080}); diff --git a/src/platform/macos/window_macos.mm b/src/platform/macos/window_macos.mm index ef8fed7..01c61f9 100644 --- a/src/platform/macos/window_macos.mm +++ b/src/platform/macos/window_macos.mm @@ -12,6 +12,40 @@ // Key for associated objects (used by both window_macos.mm and window_manager_macos.mm) const void* kWindowIdKey = &kWindowIdKey; +@interface NativeAPIWindow : NSWindow +@end + +@implementation NativeAPIWindow + +- (void)mouseUp:(NSEvent*)event { + if (event.clickCount == 2) { + if ((self.styleMask & NSWindowStyleMaskFullSizeContentView) && + self.titlebarAppearsTransparent) { + NSPoint locationInWindow = [event locationInWindow]; + NSRect contentLayoutRect = [self contentLayoutRect]; + NSRect windowFrame = [[self contentView] frame]; + + NSRect titleBarRect = NSMakeRect( + contentLayoutRect.origin.x, contentLayoutRect.origin.y + contentLayoutRect.size.height, + contentLayoutRect.size.width, windowFrame.size.height - contentLayoutRect.size.height); + + if (NSPointInRect(locationInWindow, titleBarRect)) { + NSString* action = + [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleActionOnDoubleClick"]; + if ([action isEqualToString:@"Minimize"]) { + [self miniaturize:nil]; + } else { + [self performZoom:nil]; + } + return; + } + } + } + [super mouseUp:event]; +} + +@end + namespace nativeapi { // Private implementation class @@ -39,7 +73,7 @@ if (native_window == nullptr) { // Create new platform object id = IdAllocator::Allocate(); - ns_window = [[NSWindow alloc] init]; + ns_window = [[NativeAPIWindow alloc] init]; ns_window.styleMask = NSWindowStyleMaskResizable | NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable; // Store the ID as associated object