From 7247c64c64bde6db236904d4fc9e84c15402f59e Mon Sep 17 00:00:00 2001 From: Jeremiasz Nelz Date: Fri, 16 Oct 2020 20:44:05 +0200 Subject: [PATCH] Fix logic behind Mac theme variant inference --- src/MacVim/MMVimController.m | 16 +++++++++++++++- src/MacVim/MMVimView.m | 4 ---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 7309a428f7..e6bbcface3 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -163,6 +163,8 @@ - (void)handleBrowseForFile:(NSDictionary *)attr; - (void)handleShowDialog:(NSDictionary *)attr; - (void)handleDeleteSign:(NSDictionary *)attr; - (void)setToolTipDelay:(NSTimeInterval)seconds; +- (void)themeChanged:(NSNotification *)notification; +- (void)themeChangedOnMainThread; @end @@ -201,6 +203,10 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier selector:@selector(connectionDidDie:) name:NSConnectionDidDieNotification object:connection]; + [NSDistributedNotificationCenter.defaultCenter addObserver:self + selector:@selector(themeChanged:) + name:@"AppleInterfaceThemeChangedNotification" object:nil]; + // Set up a main menu with only a "MacVim" menu (copied from a template // which itself is set up in MainMenu.nib). The main menu is populated // by Vim later on. @@ -224,7 +230,7 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier // After MMVimController's initialization is completed, // set up the variable `v:os_appearance`. - [self appearanceChanged:getCurrentAppearance([windowController vimView].effectiveAppearance)]; + [self appearanceChanged:getCurrentAppearance(NSApp.effectiveAppearance)]; return self; } @@ -1910,6 +1916,14 @@ - (void)setToolTipDelay:(NSTimeInterval)seconds } } +- (void)themeChanged:(NSNotification *)notification { + [self performSelectorOnMainThread:@selector(themeChangedOnMainThread) withObject:nil waitUntilDone:false]; +} + +- (void)themeChangedOnMainThread { + [self appearanceChanged:getCurrentAppearance(NSApp.effectiveAppearance)]; +} + @end // MMVimController (Private) diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 6624c5c6db..7b1738fc79 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -664,10 +664,6 @@ - (void)setFrame:(NSRect)frame [self frameSizeMayHaveChanged:NO]; } -- (void)viewDidChangeEffectiveAppearance -{ - [vimController appearanceChanged:getCurrentAppearance(self.effectiveAppearance)]; -} @end // MMVimView