Skip to content

Commit

Permalink
Allow never opening window + terminate on last window, with guards
Browse files Browse the repository at this point in the history
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 macvim-dev#1338
  • Loading branch information
ychin committed Nov 5, 2022
1 parent 0944187 commit cabb495
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MacVim/MMAppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
int numChildProcesses;
NSMutableDictionary *inputQueues;
int processingFlag;

BOOL hasShownWindowBefore;

#if !DISABLE_SPARKLE
#if USE_SPARKLE_1
Expand Down
11 changes: 11 additions & 0 deletions src/MacVim/MMAppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,15 @@ - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
if (!hasShownWindowBefore) {
// If we have not opened a window before, never return YES. This can
// happen when MacVim is not configured to open window at launch. We
// want to give the user a chance to open a window first. Otherwise
// just opening the About MacVim or Settings windows could immediately
// terminate the app (since those are not proper app windows),
// depending if the OS feels like invoking this method.
return NO;
}
return (MMTerminateWhenLastWindowClosed ==
[[NSUserDefaults standardUserDefaults]
integerForKey:MMLastWindowClosedBehaviorKey]);
Expand Down Expand Up @@ -888,6 +897,8 @@ - (void)windowControllerWillOpen:(MMWindowController *)windowController
[NSApp activateIgnoringOtherApps:YES];
shouldActivateWhenNextWindowOpens = NO;
}

hasShownWindowBefore = YES;
}

- (void)setMainMenu:(NSMenu *)mainMenu
Expand Down

0 comments on commit cabb495

Please sign in to comment.