From db017ae915f9e9ec71f959b08b42e5eb75d92fb8 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 25 Apr 2024 22:04:16 -0500 Subject: [PATCH 1/3] Make inverted icons configurable --- RetroBar/Controls/NotifyIcon.xaml.cs | 14 ++---- RetroBar/Controls/NotifyIconList.xaml.cs | 4 +- .../NotifyIconCanInvertConverter.cs | 26 +++++++++++ RetroBar/Extensions/NotifyIconExtensions.cs | 44 +++++++++++++++++++ RetroBar/RetroBar.csproj | 2 +- RetroBar/Utilities/Settings.cs | 21 ++++++++- 6 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 RetroBar/Converters/NotifyIconCanInvertConverter.cs create mode 100644 RetroBar/Extensions/NotifyIconExtensions.cs diff --git a/RetroBar/Controls/NotifyIcon.xaml.cs b/RetroBar/Controls/NotifyIcon.xaml.cs index e7d6146b..844a05c9 100644 --- a/RetroBar/Controls/NotifyIcon.xaml.cs +++ b/RetroBar/Controls/NotifyIcon.xaml.cs @@ -6,6 +6,7 @@ using ManagedShell.Common.Helpers; using ManagedShell.Interop; using ManagedShell.WindowsTray; +using RetroBar.Extensions; using RetroBar.Utilities; namespace RetroBar.Controls @@ -33,21 +34,12 @@ public NotifyIcon() private void applyEffects() { - if ((!EnvironmentHelper.IsWindows10OrBetter && Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.WhenNeededByTheme) || TrayIcon == null || Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.Never) + if (TrayIcon == null || Settings.Instance.InvertIconsMode == Settings.InvertIconsOption.Never) { return; } - string iconGuid = TrayIcon.GUID.ToString(); - - if (!(iconGuid == NotificationArea.HARDWARE_GUID || - iconGuid == NotificationArea.UPDATE_GUID || - iconGuid == NotificationArea.MICROPHONE_GUID || - iconGuid == NotificationArea.LOCATION_GUID || - iconGuid == NotificationArea.MEETNOW_GUID || - iconGuid == NotificationArea.NETWORK_GUID || - iconGuid == NotificationArea.POWER_GUID || - iconGuid == NotificationArea.VOLUME_GUID)) + if (!TrayIcon.CanInvert()) { return; } diff --git a/RetroBar/Controls/NotifyIconList.xaml.cs b/RetroBar/Controls/NotifyIconList.xaml.cs index 92d8f431..634039fc 100644 --- a/RetroBar/Controls/NotifyIconList.xaml.cs +++ b/RetroBar/Controls/NotifyIconList.xaml.cs @@ -51,12 +51,12 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e) NotifyIcons.ItemsSource = allNotifyIconsSource.View; } } - else if (e.PropertyName == "InvertIconsMode") + else if (e.PropertyName == "InvertIconsMode" || e.PropertyName == "InvertNotifyIcons") { // Reload icons NotifyIcons.ItemsSource = null; - if (Settings.Instance.CollapseNotifyIcons) + if (Settings.Instance.CollapseNotifyIcons && NotifyIconToggleButton.IsChecked != true) { NotifyIcons.ItemsSource = pinnedNotifyIconsSource.View; } diff --git a/RetroBar/Converters/NotifyIconCanInvertConverter.cs b/RetroBar/Converters/NotifyIconCanInvertConverter.cs new file mode 100644 index 00000000..78b27c70 --- /dev/null +++ b/RetroBar/Converters/NotifyIconCanInvertConverter.cs @@ -0,0 +1,26 @@ +using ManagedShell.WindowsTray; +using RetroBar.Extensions; +using System; +using System.Windows.Data; + +namespace RetroBar.Converters +{ + [ValueConversion(typeof(NotifyIcon), typeof(bool))] + public class NotifyIconCanInvertConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if (value is NotifyIcon icon) + { + return icon.CanInvert(); + } + + return Binding.DoNothing; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return Binding.DoNothing; + } + } +} diff --git a/RetroBar/Extensions/NotifyIconExtensions.cs b/RetroBar/Extensions/NotifyIconExtensions.cs new file mode 100644 index 00000000..ed886ec4 --- /dev/null +++ b/RetroBar/Extensions/NotifyIconExtensions.cs @@ -0,0 +1,44 @@ +using ManagedShell.WindowsTray; +using RetroBar.Utilities; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace RetroBar.Extensions +{ + public static class NotifyIconExtensions + { + + public static string GetInvertIdentifier(this NotifyIcon icon) + { + if (icon.GUID != default) return icon.GUID.ToString(); + else return icon.Path + ":" + icon.UID.ToString(); + } + + public static bool CanInvert(this NotifyIcon icon) { + return Settings.Instance.InvertNotifyIcons.Contains(icon.GetInvertIdentifier()); + } + + public static void SetCanInvert(this NotifyIcon icon, bool canInvert) + { + var identifier = icon.GetInvertIdentifier(); + var settings = new List(Settings.Instance.InvertNotifyIcons); + var changed = false; + + if (!canInvert) + { + changed = settings.Remove(identifier); + } + else if (!settings.Contains(identifier)) + { + settings.Add(identifier); + changed = true; + } + + if (changed) + { + Settings.Instance.InvertNotifyIcons = settings; + } + } + } +} diff --git a/RetroBar/RetroBar.csproj b/RetroBar/RetroBar.csproj index f2ddb47a..bc2733f0 100644 --- a/RetroBar/RetroBar.csproj +++ b/RetroBar/RetroBar.csproj @@ -45,7 +45,7 @@ - + diff --git a/RetroBar/Utilities/Settings.cs b/RetroBar/Utilities/Settings.cs index b3d17607..dd3cdd52 100644 --- a/RetroBar/Utilities/Settings.cs +++ b/RetroBar/Utilities/Settings.cs @@ -1,4 +1,6 @@ using ManagedShell.AppBar; +using ManagedShell.Common.Helpers; +using ManagedShell.WindowsTray; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; @@ -221,6 +223,23 @@ public bool CollapseNotifyIcons } } + private List _invertNotifyIcons = new List { NotificationArea.HARDWARE_GUID, NotificationArea.UPDATE_GUID, NotificationArea.MICROPHONE_GUID, NotificationArea.LOCATION_GUID, NotificationArea.MEETNOW_GUID, NotificationArea.NETWORK_GUID, NotificationArea.POWER_GUID, NotificationArea.VOLUME_GUID }; + public List InvertNotifyIcons + { + get + { + return _invertNotifyIcons; + } + set + { + if (_invertNotifyIcons != value) + { + _invertNotifyIcons = value; + OnPropertyChanged(); + } + } + } + private string[] _pinnedNotifyIcons = { "7820ae76-23e3-4229-82c1-e41cb67d5b9c", "7820ae75-23e3-4229-82c1-e41cb67d5b9c", "7820ae74-23e3-4229-82c1-e41cb67d5b9c", "7820ae73-23e3-4229-82c1-e41cb67d5b9c" }; public string[] PinnedNotifyIcons { @@ -426,7 +445,7 @@ public bool LockTaskbar } } - private InvertIconsOption _invertIconsMode = InvertIconsOption.WhenNeededByTheme; + private InvertIconsOption _invertIconsMode = EnvironmentHelper.IsWindows10OrBetter ? InvertIconsOption.WhenNeededByTheme : InvertIconsOption.Never; public InvertIconsOption InvertIconsMode { get From 4eea032ec1d360646b75e67d73cc00d0913d0966 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Sat, 27 Apr 2024 00:01:52 -0500 Subject: [PATCH 2/3] Add invert setting to customize notifications window --- RetroBar/Converters/BoolToIntConverter.cs | 7 ++- RetroBar/Languages/English.xaml | 1 + RetroBar/NotificationPropertiesWindow.xaml | 22 +++++++- RetroBar/NotificationPropertiesWindow.xaml.cs | 56 ++++++++++++++++++- RetroBar/PropertiesWindow.xaml | 3 + 5 files changed, 84 insertions(+), 5 deletions(-) diff --git a/RetroBar/Converters/BoolToIntConverter.cs b/RetroBar/Converters/BoolToIntConverter.cs index b777b1da..e0906bcb 100644 --- a/RetroBar/Converters/BoolToIntConverter.cs +++ b/RetroBar/Converters/BoolToIntConverter.cs @@ -10,7 +10,12 @@ public object Convert(object value, Type targetType, object parameter, System.Gl { if (value is bool boolValue) { - return boolValue ? 1 : 0; + var multiplier = 1; + if (parameter is string strValue) + { + multiplier = System.Convert.ToInt32(strValue); + } + return boolValue ? 1 * multiplier : 0; } return Binding.DoNothing; diff --git a/RetroBar/Languages/English.xaml b/RetroBar/Languages/English.xaml index 43bfdee5..e1d02a05 100644 --- a/RetroBar/Languages/English.xaml +++ b/RetroBar/Languages/English.xaml @@ -65,6 +65,7 @@ Always show Name Behavior + Invert Start start diff --git a/RetroBar/NotificationPropertiesWindow.xaml b/RetroBar/NotificationPropertiesWindow.xaml index 4df39564..0e928fdd 100644 --- a/RetroBar/NotificationPropertiesWindow.xaml +++ b/RetroBar/NotificationPropertiesWindow.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="clr-namespace:RetroBar.Converters" + xmlns:Settings="clr-namespace:RetroBar.Utilities" Title="{DynamicResource customize_notifications}" Height="406" Width="364" @@ -12,7 +13,9 @@ + +