diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2018-09-13 16:02:38 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@microsoft.com> | 2018-09-13 16:02:38 +0300 |
commit | d9022beab50d9ac37936b680159c18f75e7c0073 (patch) | |
tree | 34858c8e551b808049c74d50bf343e4e39c88744 | |
parent | c59be6a19c15c023c413554b62466d0e2cbdb834 (diff) |
[Ide][Mac] Support instant Ide theme switching on Mojavemojave-dark-theme-interactive
5 files changed, 69 insertions, 19 deletions
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index 1d009b5e21..a1e752aaa4 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -452,20 +452,40 @@ namespace MonoDevelop.MacIntegration if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) { IdeApp.Workbench.RootWindow.Realized += (sender, args) => { - var win = GtkQuartz.GetWindow ((Gtk.Window) sender); + var win = GtkQuartz.GetWindow ((Gtk.Window)sender); win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary; if (MacSystemInformation.OsVersion >= MacSystemInformation.Sierra) win.TabbingMode = NSWindowTabbingMode.Disallowed; }; } + if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave && string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceThemeName)) + IdeTheme.UpdateGtkTheme (); // reload Gtk theme to take system theme into account + PatchGtkTheme (); - NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( - delegate { - Styles.LoadStyle(); - PatchGtkTheme(); + + if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { + NSNotificationCenter.DefaultCenter.AddObserver (new NSString ("HIMenuBarAppearanceDidChangeNotification"), notif => Core.Runtime.RunInMainThread ( + delegate { + // reload theme only if UserInterfaceThemeName is not set + if (string.IsNullOrEmpty (IdeApp.Preferences.UserInterfaceThemeName)) { + // HACK: AppleInterfaceStyle is only set in dark OS theme mode, otherwise it's null + var macOsTheme = NSUserDefaults.StandardUserDefaults.StringForKey (new NSString ("AppleInterfaceStyle")) == "Dark" ? Theme.Dark : Theme.Light; + if (IdeTheme.UserInterfaceTheme != macOsTheme) { + IdeTheme.UpdateGtkTheme (); + PatchGtkTheme (); + } + } })); + NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread ( + delegate { + IdeTheme.UpdateGtkTheme (); + PatchGtkTheme (); + })); + + IdeApp.Preferences.UserInterfaceThemeName.Changed += (s, a) => PatchGtkTheme (); + } if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave) { // the shared color panel has full automatic theme support on Mojave Styles.Changed += (s, a) => { @@ -481,9 +501,6 @@ namespace MonoDevelop.MacIntegration UpdateColorPanelSubviewsAppearance (colorPanel.ContentView.Superview, appearance); }; } - - // FIXME: Immediate theme switching disabled, until NSAppearance issues are fixed - //IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme (); } static void UpdateColorPanelSubviewsAppearance (NSView view, NSAppearance appearance) diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs index 5ab781ecb9..fb158365bc 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.OptionPanels/HighlightingPanel.cs @@ -74,6 +74,7 @@ namespace MonoDevelop.SourceEditor.OptionPanels void HandleThemeChanged (object sender, EventArgs e) { ShowStyles (); + schemeName = DefaultSourceEditorOptions.Instance.EditorTheme; } protected override void OnDestroyed () diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/IdeTheme.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/IdeTheme.cs index 685f5e4a4d..e2c12405db 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/IdeTheme.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/IdeTheme.cs @@ -51,10 +51,12 @@ namespace MonoDevelop.Components { DefaultGtkDataFolder = Environment.GetEnvironmentVariable ("GTK_DATA_PREFIX"); DefaultGtk2RcFiles = Environment.GetEnvironmentVariable ("GTK2_RC_FILES"); - // FIXME: Immediate theme switching disabled, until: - // MAC: NSAppearance issues are fixed - // WIN: spradic Gtk crashes on theme realoding are fixed - //IdeApp.Preferences.UserInterfaceTheme.Changed += (sender, e) => UpdateGtkTheme (); + // FIXME: Immediate theme switching disabled: + // MAC: NSAppearance issues in High Sierra and older macOS versions + // WIN: spradic Gtk crashes on theme realoding + // Linux: TODO + if (Platform.IsMac && MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) + IdeApp.Preferences.UserInterfaceThemeName.Changed += (sender, e) => UpdateGtkTheme (); } internal static bool AccessibilityEnabled { get; private set; } @@ -154,6 +156,23 @@ namespace MonoDevelop.Components if (!Platform.IsLinux) { UserInterfaceTheme = IdeApp.Preferences.UserInterfaceThemeName == "Dark" ? Theme.Dark : Theme.Light; + #if MAC + if (Platform.IsMac && MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) { + // HACK: on Mojave the Gtk theme needs to be loaded twice to take the system theme setting into account. + // During the first run we load the default light theme in order to initialize Gtk correctly and + // after NSApplication initialization we need to reload the Gtk theme. + + // NSApplication.Initialized will be set by Xwt during NSApplication initialization + var xamMacInitialized = System.Threading.Thread.GetData (System.Threading.Thread.GetNamedDataSlot ("NSApplication.Initialized")) as bool? == true; + var userDefaults = !xamMacInitialized ? null : NSUserDefaults.StandardUserDefaults; + + if (userDefaults != null && string.IsNullOrEmpty(IdeApp.Preferences.UserInterfaceThemeName)) { + // use os theme setting, if UserInterfaceThemeName is not set + var macOsTheme = NSUserDefaults.StandardUserDefaults.StringForKey (new NSString ("AppleInterfaceStyle")); + UserInterfaceTheme = macOsTheme == "Dark" ? Theme.Dark : Theme.Light; + } + } + #endif if (current_theme != UserInterfaceTheme.ToString ()) // Only theme names allowed on Win/Mac current_theme = UserInterfaceTheme.ToString (); } @@ -352,6 +371,7 @@ namespace MonoDevelop.Components if (IdeApp.Preferences.UserInterfaceTheme == Theme.Light) { window.StyleMask &= ~NSWindowStyle.TexturedBackground; window.BackgroundColor = MonoDevelop.Ide.Gui.Styles.BackgroundColor.ToNSColor (); + window.TitlebarAppearsTransparent = false; return; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/IDEStyleOptionsPanel.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/IDEStyleOptionsPanel.cs index ec443dd299..e512f7a418 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/IDEStyleOptionsPanel.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.OptionPanels/IDEStyleOptionsPanel.cs @@ -58,7 +58,7 @@ namespace MonoDevelop.Ide.Gui.OptionPanels partial class IDEStyleOptionsPanelWidget : Gtk.Bin { - string currentTheme; + string selectedTheme, currentTheme; static Lazy<Dictionary<string, string>> themes = new Lazy<Dictionary<string, string>> (() => { var searchDirs = new List<string> (); @@ -99,7 +99,7 @@ namespace MonoDevelop.Ide.Gui.OptionPanels void Load () { - currentTheme = IdeApp.Preferences.UserInterfaceThemeName; + selectedTheme = currentTheme = IdeApp.Preferences.UserInterfaceThemeName; foreach (var localeSet in LocalizationService.CurrentLocaleSet) comboLanguage.AppendText (localeSet.DisplayName); @@ -142,7 +142,9 @@ namespace MonoDevelop.Ide.Gui.OptionPanels { bool restartRequired = false; - if (currentTheme != IdeApp.Preferences.UserInterfaceThemeName.Value || + bool themeNeedsRestartOnMac = Platform.IsMac && MacSystemInformation.OsVersion < MacSystemInformation.Mojave; + + if (themeNeedsRestartOnMac && selectedTheme != IdeApp.Preferences.UserInterfaceThemeName.Value || ((Platform.IsLinux && Gtk.Settings.Default.ThemeName != IdeApp.Preferences.UserInterfaceThemeName.Value) || IdeTheme.UserInterfaceTheme != (IdeApp.Preferences.UserInterfaceThemeName == "Dark" ? Theme.Dark : Theme.Light))) restartRequired = true; @@ -175,9 +177,12 @@ namespace MonoDevelop.Ide.Gui.OptionPanels void SetTheme (string theme) { if (theme.Length == 0 && Platform.IsLinux) { - currentTheme = ""; + selectedTheme = ""; } else { - currentTheme = theme; + selectedTheme = theme; + if (Platform.IsMac && MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) + if (selectedTheme != IdeApp.Preferences.UserInterfaceThemeName.Value) + IdeApp.Preferences.UserInterfaceThemeName.Value = selectedTheme; } } @@ -220,8 +225,15 @@ namespace MonoDevelop.Ide.Gui.OptionPanels if (lc != IdeApp.Preferences.UserInterfaceLanguage) IdeApp.Preferences.UserInterfaceLanguage.Value = lc; + if (selectedTheme != currentTheme) + IdeApp.Preferences.UserInterfaceThemeName.Value = currentTheme = selectedTheme; + } + + public override void Destroy () + { if (currentTheme != IdeApp.Preferences.UserInterfaceThemeName.Value) - IdeApp.Preferences.UserInterfaceThemeName.Value = currentTheme; + IdeApp.Preferences.UserInterfaceThemeName.Value = selectedTheme = currentTheme; + base.Destroy (); } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdePreferences.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdePreferences.cs index 3cc2a568e8..8549e5d59d 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdePreferences.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdePreferences.cs @@ -116,7 +116,7 @@ namespace MonoDevelop.Ide } public readonly ConfigurationProperty<string> UserInterfaceLanguage = Runtime.Preferences.UserInterfaceLanguage; - public readonly ConfigurationProperty<string> UserInterfaceThemeName = ConfigurationProperty.Create ("MonoDevelop.Ide.UserInterfaceTheme", Platform.IsLinux ? "" : "Light"); + public readonly ConfigurationProperty<string> UserInterfaceThemeName = ConfigurationProperty.Create ("MonoDevelop.Ide.UserInterfaceTheme", string.Empty); public readonly ConfigurationProperty<WorkbenchCompactness> WorkbenchCompactness = ConfigurationProperty.Create ("MonoDevelop.Ide.WorkbenchCompactness", MonoDevelop.Ide.WorkbenchCompactness.Normal); public readonly ConfigurationProperty<bool> LoadPrevSolutionOnStartup = ConfigurationProperty.Create ("SharpDevelop.LoadPrevProjectOnStartup", false); public readonly ConfigurationProperty<bool> CreateFileBackupCopies = ConfigurationProperty.Create ("SharpDevelop.CreateBackupCopy", false); |