Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 8b7ee7a

Browse files
authored
Merge pull request #9256 from mono/backport-pr-9228-to-release-8.4
[release-8.4] [Mac] Add initial high contrast theme support
2 parents e83db57 + 3def6c8 commit 8b7ee7a

File tree

86 files changed

+138
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+138
-8
lines changed

main/src/addins/MacPlatform/MacPlatform.cs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public class MacPlatformService : PlatformService
7272

7373
static bool initedGlobal;
7474
bool setupFail, initedApp;
75+
// hold a reference on all observer objects generated by the notification center
76+
// NOTE: these objects should not be actively disposed on macOS 10.11 and later, unless removed manually
77+
// not keeping a reference might cause a runtime crash when observers are added:
78+
// KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED
79+
List<IDisposable> notificationObservers = new List<IDisposable> ();
7580

7681
readonly Lazy<Dictionary<string, string>> mimemap = new Lazy<Dictionary<string, string>> (LoadMimeMap);
7782

@@ -317,12 +322,12 @@ public override Xwt.Toolkit LoadNativeToolkit ()
317322
SwizzleNSApplication ();
318323

319324
var nc = NSNotificationCenter.DefaultCenter;
320-
nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
325+
notificationObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
321326
LoggingService.LogInfo ($"VoiceOver on {IdeTheme.AccessibilityEnabled}");
322327
if (!IdeTheme.AccessibilityEnabled) {
323328
ShowVoiceOverNotice ();
324329
}
325-
}, NSApplication.SharedApplication);
330+
}, NSApplication.SharedApplication));
326331

327332
// Now that Cocoa has been initialized we can check whether the keyboard focus mode is turned on
328333
// See System Preferences - Keyboard - Shortcuts - Full Keyboard Access
@@ -568,12 +573,23 @@ void InitApp (CommandManager commandManager)
568573
};
569574

570575
PatchGtkTheme ();
571-
NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
572-
delegate {
573-
Styles.LoadStyle();
574-
PatchGtkTheme();
575-
}));
576576

577+
if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) {
578+
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
579+
notificationObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif =>
580+
Core.Runtime.RunInMainThread (() => {
581+
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
582+
PatchGtkTheme ();
583+
})
584+
));
585+
} else {
586+
IdeTheme.HighContrastThemeEnabled = false;
587+
notificationObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
588+
delegate {
589+
Styles.LoadStyle ();
590+
PatchGtkTheme ();
591+
})));
592+
}
577593

578594
if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave) { // the shared color panel has full automatic theme support on Mojave
579595
Styles.Changed += (s, a) => {
@@ -594,6 +610,18 @@ void InitApp (CommandManager commandManager)
594610
//IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme ();
595611
}
596612

613+
static bool GetIsHighContrastActive ()
614+
{
615+
var highContrastAppearances = new string [] {
616+
NSAppearance.NameAccessibilityHighContrastAqua,
617+
NSAppearance.NameAccessibilityHighContrastDarkAqua,
618+
NSAppearance.NameAccessibilityHighContrastVibrantDark,
619+
NSAppearance.NameAccessibilityHighContrastVibrantLight,
620+
};
621+
// FindBestMatch will return the best matching a11y appearance or null if no high contrast appearance is in use
622+
return NSApplication.SharedApplication.EffectiveAppearance.FindBestMatch (highContrastAppearances) != null;
623+
}
624+
597625
static void UpdateColorPanelSubviewsAppearance (NSView view, NSAppearance appearance)
598626
{
599627
if (view.Class.Name == "NSPageableTableView")

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@
307307
<EmbeddedResource Include="icons\gutter-stack-15%402x.png" />
308308
<EmbeddedResource Include="icons\gutter-stack-15~dark.png" />
309309
<EmbeddedResource Include="icons\gutter-stack-15~dark%402x.png" />
310+
<EmbeddedResource Include="icons\gutter-stack-15~contrast.png" />
311+
<EmbeddedResource Include="icons\gutter-stack-15~contrast%402x.png" />
310312
<EmbeddedResource Include="icons\gutter-tracepoint-15.png" />
311313
<EmbeddedResource Include="icons\gutter-tracepoint-15%402x.png" />
312314
<EmbeddedResource Include="icons\gutter-tracepoint-15~dark.png" />
@@ -333,6 +335,8 @@
333335
<EmbeddedResource Include="icons\stack-pointer-16~disabled%402x.png" />
334336
<EmbeddedResource Include="icons\stack-pointer-16~dark~disabled.png" />
335337
<EmbeddedResource Include="icons\stack-pointer-16~dark~disabled%402x.png" />
338+
<EmbeddedResource Include="icons\stack-pointer-16~contrast.png" />
339+
<EmbeddedResource Include="icons\stack-pointer-16~contrast%402x.png" />
336340
</ItemGroup>
337341
<ItemGroup Condition=" '$(Configuration)' != 'DebugMac' AND '$(Configuration)' != 'ReleaseMac' ">
338342
<EmbeddedResource Include="icons\pause-16.png" />
153 Bytes
237 Bytes
152 Bytes
240 Bytes

main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@
290290
<EmbeddedResource Include="icons\issues-ok-16%402x.png" />
291291
<EmbeddedResource Include="icons\issues-ok-16~dark.png" />
292292
<EmbeddedResource Include="icons\issues-ok-16~dark%402x.png" />
293+
<EmbeddedResource Include="icons\issues-ok-16~contrast.png" />
294+
<EmbeddedResource Include="icons\issues-ok-16~contrast%402x.png" />
293295
<EmbeddedResource Include="icons\issues-suggestion-16.png" />
294296
<EmbeddedResource Include="icons\issues-suggestion-16%402x.png" />
295297
<EmbeddedResource Include="icons\issues-suggestion-16~dark.png" />
157 Bytes
144 Bytes

main/src/addins/MonoDevelop.TextEditor/MonoDevelop.TextEditor.Cocoa/MonoDevelop.TextEditor.Cocoa.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@
129129
<None Remove="icons\vs-find-replace-search-16%402x.png" />
130130
<None Remove="icons\go-up-16.png" />
131131
<None Remove="icons\go-up-16%402x.png" />
132+
<None Remove="icons\go-up-16~contrast.png" />
133+
<None Remove="icons\go-up-16~contrast%402x.png" />
132134
<None Remove="icons\go-down-16.png" />
133135
<None Remove="icons\go-down-16%402x.png" />
136+
<None Remove="icons\go-down-16~contrast.png" />
137+
<None Remove="icons\go-down-16~contrast%402x.png" />
134138
</ItemGroup>
135139
<ItemGroup>
136140
<EmbeddedResource Include="icons\vs-find-replace-close-16.png" />
@@ -151,8 +155,12 @@
151155
<EmbeddedResource Include="icons\vs-find-replace-search-16%402x.png" />
152156
<EmbeddedResource Include="icons\go-up-16.png" />
153157
<EmbeddedResource Include="icons\go-up-16%402x.png" />
158+
<EmbeddedResource Include="icons\go-up-16~contrast.png" />
159+
<EmbeddedResource Include="icons\go-up-16~contrast%402x.png" />
154160
<EmbeddedResource Include="icons\go-down-16.png" />
155161
<EmbeddedResource Include="icons\go-down-16%402x.png" />
162+
<EmbeddedResource Include="icons\go-down-16~contrast.png" />
163+
<EmbeddedResource Include="icons\go-down-16~contrast%402x.png" />
156164
</ItemGroup>
157165
<Target Name="BuildTextMate" BeforeTargets="Compile">
158166
<MSBuild Projects="$(VSEditorCoreDirectory)src\TextMate\TMRegEx\TMRegEx.proj" Targets="Build" Properties="Configuration=$(Configuration)" />

0 commit comments

Comments
 (0)