Skip to content

Commit cabb495

Browse files
committed
Allow never opening window + terminate on last window, with guards
Previously we disabled this combo in f6ba7dd because when implemented naively, it causes an issue where just opening an About MacVim or Settings window could immediately cause MacVim to exit (because macOS determined that there were no non-auxillary window open). This was awkward and potentially made it hard to change the setting back, and exact behavior depended on OS behavior. However, it seems like there are legit use case for this combo of settings. Change it so that we allow setting both of them again, but add checks so that `applicationShouldTerminateAfterLastWindowClosed:` will only return `YES` if we have opened at least one Vim window before. This gives the user a chance to open a window first, so using Settings etc wouldn't immediately terminate the app. Fix #1338
1 parent 0944187 commit cabb495

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/MacVim/MMAppController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
int numChildProcesses;
5050
NSMutableDictionary *inputQueues;
5151
int processingFlag;
52+
53+
BOOL hasShownWindowBefore;
5254

5355
#if !DISABLE_SPARKLE
5456
#if USE_SPARKLE_1

src/MacVim/MMAppController.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,15 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
548548

549549
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
550550
{
551+
if (!hasShownWindowBefore) {
552+
// If we have not opened a window before, never return YES. This can
553+
// happen when MacVim is not configured to open window at launch. We
554+
// want to give the user a chance to open a window first. Otherwise
555+
// just opening the About MacVim or Settings windows could immediately
556+
// terminate the app (since those are not proper app windows),
557+
// depending if the OS feels like invoking this method.
558+
return NO;
559+
}
551560
return (MMTerminateWhenLastWindowClosed ==
552561
[[NSUserDefaults standardUserDefaults]
553562
integerForKey:MMLastWindowClosedBehaviorKey]);
@@ -888,6 +897,8 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
888897
[NSApp activateIgnoringOtherApps:YES];
889898
shouldActivateWhenNextWindowOpens = NO;
890899
}
900+
901+
hasShownWindowBefore = YES;
891902
}
892903

893904
- (void)setMainMenu:(NSMenu *)mainMenu

0 commit comments

Comments
 (0)