From 8ffd069689d9ad81a8492b5e01ecb85bada604d4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 22 Jun 2016 14:06:54 +0900 Subject: [PATCH] mac: Fix maximize/unmaximize event emitted before window is maximized --- atom/browser/native_window_mac.mm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 5f997ee9b6b9..3330eb8e9f3e 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -70,6 +70,7 @@ bool ScopedDisableResize::disable_resize_ = false; @interface AtomNSWindowDelegate : NSObject { @private atom::NativeWindowMac* shell_; + bool is_zooming_; } - (id)initWithShell:(atom::NativeWindowMac*)shell; @end @@ -79,6 +80,7 @@ bool ScopedDisableResize::disable_resize_ = false; - (id)initWithShell:(atom::NativeWindowMac*)shell { if ((self = [super init])) { shell_ = shell; + is_zooming_ = false; } return self; } @@ -172,16 +174,20 @@ bool ScopedDisableResize::disable_resize_ = false; } - (BOOL)windowShouldZoom:(NSWindow*)window toFrame:(NSRect)newFrame { - // Cocoa doen't have concept of maximize/unmaximize, so wee need to emulate - // them by calculating size change when zooming. - if (newFrame.size.width < [window frame].size.width || - newFrame.size.height < [window frame].size.height) - shell_->NotifyWindowUnmaximize(); - else - shell_->NotifyWindowMaximize(); + is_zooming_ = true; return YES; } +- (void)windowDidEndLiveResize:(NSNotification*)notification { + if (is_zooming_) { + if (shell_->IsMaximized()) + shell_->NotifyWindowMaximize(); + else + shell_->NotifyWindowUnmaximize(); + is_zooming_ = false; + } +} + - (void)windowWillEnterFullScreen:(NSNotification*)notification { // Hide the native toolbar before entering fullscreen, so there is no visual // artifacts.