diff --git a/main/external/xwt b/main/external/xwt index 0b54869e244..e159b80639e 160000 --- a/main/external/xwt +++ b/main/external/xwt @@ -1 +1 @@ -Subproject commit 0b54869e24438f1b36aee977e799f0b82481ed7b +Subproject commit e159b80639ec01d2551cbcb1e039b96dd592d2c8 diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index a7047b4c4ac..48978a219e6 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -289,6 +289,8 @@ static void RegisterUncaughtExceptionHandler () NSSetUncaughtExceptionHandler (uncaughtHandler); } + internal static List AllObservers { get; } = new List (); + public override Xwt.Toolkit LoadNativeToolkit () { var loaded = NativeToolkitHelper.LoadCocoa (); @@ -307,6 +309,10 @@ public override Xwt.Toolkit LoadNativeToolkit () var appDelegate = NSApplication.SharedApplication.Delegate as Xwt.Mac.AppDelegate; if (appDelegate != null) { appDelegate.Terminating += async (object o, TerminationEventArgs e) => { + foreach (var observer in AllObservers) + observer.Dispose (); + AllObservers.Clear (); + if (MonoDevelop.Ide.IdeApp.IsRunning) { // If GLib the mainloop is still running that means NSApplication.Terminate() was called // before Gtk.Application.Quit(). Cancel Cocoa termination and exit the mainloop. @@ -319,6 +325,9 @@ public override Xwt.Toolkit LoadNativeToolkit () e.Reply = NSApplicationTerminateReply.Now; } }; + + // TODO: only attach this if coverage profiler is on + appDelegate.Terminate += () => Environment.Exit (0); appDelegate.ShowDockMenu += AppDelegate_ShowDockMenu; } @@ -326,7 +335,7 @@ public override Xwt.Toolkit LoadNativeToolkit () SwizzleNSApplication (); var nc = NSNotificationCenter.DefaultCenter; - notificationObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => { + AllObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => { LoggingService.LogInfo ($"VoiceOver on {IdeTheme.AccessibilityEnabled}"); if (!IdeTheme.AccessibilityEnabled) { ShowVoiceOverNotice (); @@ -582,7 +591,7 @@ void InitApp (CommandManager commandManager) if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive (); - notificationObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif => + AllObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif => Core.Runtime.RunInMainThread (() => { IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive (); PatchGtkTheme (); @@ -590,7 +599,7 @@ void InitApp (CommandManager commandManager) )); } else { IdeTheme.HighContrastThemeEnabled = false; - notificationObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( + AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( delegate { Styles.LoadStyle (); PatchGtkTheme (); diff --git a/main/src/addins/MacPlatform/MainToolbar/AwesomeBar.cs b/main/src/addins/MacPlatform/MainToolbar/AwesomeBar.cs index 86af18a505f..c250fa03d3f 100644 --- a/main/src/addins/MacPlatform/MainToolbar/AwesomeBar.cs +++ b/main/src/addins/MacPlatform/MainToolbar/AwesomeBar.cs @@ -144,7 +144,7 @@ public override void ViewDidMoveToWindow () public override void ViewWillMoveToSuperview (NSView newSuperview) { if (Superview != null && superviewFrameChangeObserver != null) { - NSNotificationCenter.DefaultCenter.RemoveObserver (superviewFrameChangeObserver); + superviewFrameChangeObserver.Dispose (); superviewFrameChangeObserver = null; Superview.PostsFrameChangedNotifications = false; diff --git a/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs b/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs index 1626f472506..31727d974dc 100644 --- a/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs +++ b/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs @@ -192,12 +192,12 @@ public MainToolbar (Gtk.Window window) item.MinSize = size; } }); - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction, nswin); - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction, nswin); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction, nswin)); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction, nswin)); } - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin); - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen = false, nswin); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillEnterFullScreenNotification, (note) => IsFullscreen = true, nswin)); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillExitFullScreenNotification, (note) => IsFullscreen = false, nswin)); } internal void Initialize () diff --git a/main/src/addins/MacPlatform/MainToolbar/SearchBar.cs b/main/src/addins/MacPlatform/MainToolbar/SearchBar.cs index 3acaf0a4866..5f010142e0c 100644 --- a/main/src/addins/MacPlatform/MainToolbar/SearchBar.cs +++ b/main/src/addins/MacPlatform/MainToolbar/SearchBar.cs @@ -243,7 +243,7 @@ void UpdateLayout () void Initialize () { - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResignKeyNotification, notification => Runtime.RunInMainThread (() => { + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResignKeyNotification, notification => Runtime.RunInMainThread (() => { var other = (NSWindow)notification.Object; if (notification.Object == Window) { @@ -252,8 +252,8 @@ void Initialize () LostFocus (this, null); } } - })); - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notification => Runtime.RunInMainThread (() => { + }))); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notification => Runtime.RunInMainThread (() => { var other = (NSWindow)notification.Object; if (notification.Object == Window) { if (IsFirstResponderOfWindow (Window)) { @@ -261,7 +261,7 @@ void Initialize () LostFocus (this, null); } } - })); + }))); } bool IsFirstResponderOfWindow (NSWindow window) diff --git a/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs b/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs index 3fb5e464b6e..3617e8fc153 100644 --- a/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs +++ b/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs @@ -788,8 +788,8 @@ public override void ViewDidMoveToWindow () { base.ViewDidMoveToWindow (); - NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidChangeBackingPropertiesNotification, - notification => Runtime.RunInMainThread ((Action) RealignTexts)); + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidChangeBackingPropertiesNotification, + notification => Runtime.RunInMainThread ((Action) RealignTexts))); RealignTexts (); } diff --git a/main/src/addins/MacPlatform/ScreenMonitor.cs b/main/src/addins/MacPlatform/ScreenMonitor.cs index ce0361ce905..3e176a73f45 100644 --- a/main/src/addins/MacPlatform/ScreenMonitor.cs +++ b/main/src/addins/MacPlatform/ScreenMonitor.cs @@ -56,9 +56,9 @@ public static class ScreenMonitor static ScreenMonitor () { screenToGdk = UpdateScreenLayout (); - NSNotificationCenter.DefaultCenter.AddObserver (NSApplication.DidChangeScreenParametersNotification, (obj) => { + MacPlatformService.AllObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSApplication.DidChangeScreenParametersNotification, (obj) => { screenToGdk = UpdateScreenLayout (); - }); + })); } public static CGPoint GdkPointForNSScreen (NSScreen screen)