From c25e4c8973579a006e0eb978abc0d7330993a8c6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 13 Jun 2016 01:35:43 +0400 Subject: [PATCH] OS X: sort out window visibility and focus. --- src/cocoa/cocoamain.mm | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cocoa/cocoamain.mm b/src/cocoa/cocoamain.mm index d911ddc..b6fb7d1 100644 --- a/src/cocoa/cocoamain.mm +++ b/src/cocoa/cocoamain.mm @@ -400,7 +400,7 @@ CONVERT(Rect) .x = xy.x + size.width / 2, .y = xy.y - size.height / 2 }; - [[self window] becomeKeyWindow]; + [[self window] makeKeyWindow]; [super startEditing:text at:[self convertPointFromBacking:point] withHeight:fontHeight usingMonospace:FALSE]; [self prepareEditorWithMinWidthInChars:minWidthChars]; @@ -1030,6 +1030,11 @@ void InitTextWindow() { [TW setBecomesKeyOnlyIfNeeded:YES]; [GW addChildWindow:TW ordered:NSWindowAbove]; + // Without this, graphics window is also hidden when the text window is shown + // (and is its child window). We replicate the standard behavior manually, in + // the application delegate; + [TW setHidesOnDeactivate:NO]; + NSScrollView *scrollView = [[NSScrollView alloc] init]; [TW setContentView:scrollView]; [scrollView setBackgroundColor:[NSColor blackColor]]; @@ -1047,9 +1052,9 @@ void InitTextWindow() { void ShowTextWindow(bool visible) { if(visible) - [TW orderFront:nil]; + [GW addChildWindow:TW ordered:NSWindowAbove]; else - [TW close]; + [TW orderOut:GW]; } void GetTextWindowSize(int *w, int *h) { @@ -1140,6 +1145,8 @@ std::vector SolveSpace::GetFontFiles() { - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; - (void)applicationWillTerminate:(NSNotification *)aNotification; +- (void)applicationWillBecomeActive:(NSNotification *)aNotification; +- (void)applicationWillResignActive:(NSNotification *)aNotification; - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename; - (IBAction)preferences:(id)sender; @end @@ -1160,6 +1167,18 @@ std::vector SolveSpace::GetFontFiles() { SolveSpace::SS.Exit(); } +- (void)applicationWillBecomeActive:(NSNotification *)aNotification { + if(SolveSpace::SS.GW.showTextWindow) { + [GW addChildWindow:TW ordered:NSWindowAbove]; + } +} + +- (void)applicationWillResignActive:(NSNotification *)aNotification { + [TW setAnimationBehavior:NSWindowAnimationBehaviorNone]; + [TW orderOut:nil]; + [TW setAnimationBehavior:NSWindowAnimationBehaviorDefault]; +} + - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { return SolveSpace::SS.OpenFile([filename UTF8String]); } @@ -1187,7 +1206,6 @@ int main(int argc, const char *argv[]) { SolveSpace::SS.Init(); [GW makeKeyAndOrderFront:nil]; - [NSApp activateIgnoringOtherApps:YES]; [NSApp run]; SolveSpace::SK.Clear();