diff options
Diffstat (limited to 'main/src/addins/MacPlatform/MacPlatform.cs')
-rw-r--r-- | main/src/addins/MacPlatform/MacPlatform.cs | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 954c597a4a..54aaacc5c4 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -72,6 +72,11 @@ namespace MonoDevelop.MacIntegration static bool initedGlobal; bool setupFail, initedApp; + // hold a reference on all observer objects generated by the notification center + // NOTE: these objects should not be actively disposed on macOS 10.11 and later, unless removed manually + // not keeping a reference might cause a runtime crash when observers are added: + // KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + List<IDisposable> notificationObservers = new List<IDisposable> (); readonly Lazy<Dictionary<string, string>> mimemap = new Lazy<Dictionary<string, string>> (LoadMimeMap); @@ -317,12 +322,12 @@ namespace MonoDevelop.MacIntegration SwizzleNSApplication (); var nc = NSNotificationCenter.DefaultCenter; - nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => { + notificationObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => { LoggingService.LogInfo ($"VoiceOver on {IdeTheme.AccessibilityEnabled}"); if (!IdeTheme.AccessibilityEnabled) { ShowVoiceOverNotice (); } - }, NSApplication.SharedApplication); + }, NSApplication.SharedApplication)); // Now that Cocoa has been initialized we can check whether the keyboard focus mode is turned on // See System Preferences - Keyboard - Shortcuts - Full Keyboard Access @@ -568,12 +573,23 @@ namespace MonoDevelop.MacIntegration }; PatchGtkTheme (); - NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( - delegate { - Styles.LoadStyle(); - PatchGtkTheme(); - })); + if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { + IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive (); + notificationObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif => + Core.Runtime.RunInMainThread (() => { + IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive (); + PatchGtkTheme (); + }) + )); + } else { + IdeTheme.HighContrastThemeEnabled = false; + notificationObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( + delegate { + Styles.LoadStyle (); + PatchGtkTheme (); + }))); + } if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave) { // the shared color panel has full automatic theme support on Mojave Styles.Changed += (s, a) => { @@ -594,6 +610,18 @@ namespace MonoDevelop.MacIntegration //IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme (); } + static bool GetIsHighContrastActive () + { + var highContrastAppearances = new string [] { + NSAppearance.NameAccessibilityHighContrastAqua, + NSAppearance.NameAccessibilityHighContrastDarkAqua, + NSAppearance.NameAccessibilityHighContrastVibrantDark, + NSAppearance.NameAccessibilityHighContrastVibrantLight, + }; + // FindBestMatch will return the best matching a11y appearance or null if no high contrast appearance is in use + return NSApplication.SharedApplication.EffectiveAppearance.FindBestMatch (highContrastAppearances) != null; + } + static void UpdateColorPanelSubviewsAppearance (NSView view, NSAppearance appearance) { if (view.Class.Name == "NSPageableTableView") |