Skip to content

Commit 90697d9

Browse files
committed
Add customizable background style (#787)
Closes #787
1 parent e958a6f commit 90697d9

13 files changed

Lines changed: 563 additions & 173 deletions

File tree

‎EverythingToolbar.App/ToolbarSettings.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,14 @@ public interface IToolbarSettings
160160

161161
[Option(DefaultValue = false)]
162162
bool IsForceLegacySdk { get; set; }
163+
164+
[Option(DefaultValue = "Automatic")]
165+
string SearchWindowBackground { get; set; }
166+
167+
[Option(DefaultValue = 218)]
168+
int SearchWindowBackgroundAlpha { get; set; }
169+
170+
[Option(DefaultValue = 37)]
171+
int SearchWindowBackgroundBrightness { get; set; }
163172
}
164173
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Windows.Media;
3+
4+
namespace EverythingToolbar.Helpers
5+
{
6+
public static class ColorHelper
7+
{
8+
public const int DefaultAlpha = 0xDA;
9+
public const int DefaultBrightness = 0x25;
10+
public static readonly Color DefaultSearchWindowColor = Color.FromArgb(DefaultAlpha, DefaultBrightness, DefaultBrightness, DefaultBrightness);
11+
12+
public static Color GetSearchWindowColor(int alpha, int brightness, bool isLight)
13+
{
14+
byte clampedAlpha = (byte)Math.Clamp(alpha, 0, 255);
15+
int clampedBrightness = Math.Clamp(brightness, 0, 100);
16+
byte gray = (byte)(isLight ? 255 - clampedBrightness : clampedBrightness);
17+
return Color.FromArgb(clampedAlpha, gray, gray, gray);
18+
}
19+
20+
public static string ToHex(Color color) => $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
21+
22+
public static SolidColorBrush ToFrozenBrush(Color color)
23+
{
24+
var brush = new SolidColorBrush(color);
25+
brush.Freeze();
26+
return brush;
27+
}
28+
}
29+
}

‎EverythingToolbar/Properties/Resources.Designer.cs‎

Lines changed: 55 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎EverythingToolbar/Properties/Resources.resx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,22 @@
771771
<data name="SettingsForceLegacySdkHelp" xml:space="preserve">
772772
<value>Always use the legacy IPC client, which may be more compatible but slower.</value>
773773
</data>
774+
<data name="SettingsSearchWindowBackground" xml:space="preserve">
775+
<value>Search window background</value>
776+
</data>
777+
<data name="SettingsSearchWindowBackgroundHelp" xml:space="preserve">
778+
<value>Choose the background tone for the search window</value>
779+
</data>
780+
<data name="SearchWindowBackgroundAutomatic" xml:space="preserve">
781+
<value>Automatic</value>
782+
</data>
783+
<data name="SearchWindowBackgroundCustom" xml:space="preserve">
784+
<value>Custom</value>
785+
</data>
786+
<data name="ColorPickerAlpha" xml:space="preserve">
787+
<value>Alpha</value>
788+
</data>
789+
<data name="ColorPickerBrightness" xml:space="preserve">
790+
<value>Brightness</value>
791+
</data>
774792
</root>

‎EverythingToolbar/SearchWindow.xaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<controls:AcrylicWindow
1+
<controls:AcrylicWindow
22
x:Class="EverythingToolbar.SearchWindow"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -27,7 +27,7 @@
2727
<b:Themed Surface="TaskbarSurface" />
2828
</i:Interaction.Behaviors>
2929

30-
<Border Background="{DynamicResource SearchResultsViewHeader}">
30+
<Border Background="{DynamicResource SearchWindowBackground}">
3131
<Grid Name="ContentGrid">
3232
<Grid.RowDefinitions>
3333
<RowDefinition Height="{DynamicResource FirstGridRowHeight}" />

‎EverythingToolbar/Services/ThemeService.cs‎

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Linq;
55
using System.Threading;
66
using System.Windows;
77
using System.Windows.Media;
88
using System.Windows.Threading;
9+
using EverythingToolbar.Helpers;
910
using NLog;
1011
using Windows.UI.ViewManagement;
1112
using Wpf.Ui.Appearance;
@@ -166,7 +167,14 @@ private void ScheduleApply()
166167

167168
private void OnSettingsChanged(object? sender, PropertyChangedEventArgs e)
168169
{
169-
if (e.PropertyName is nameof(ISettings.ThemeOverride) or nameof(ISettings.ForceWin10Behavior))
170+
if (
171+
e.PropertyName
172+
is nameof(ISettings.ThemeOverride)
173+
or nameof(ISettings.ForceWin10Behavior)
174+
or nameof(ISettings.SearchWindowBackground)
175+
or nameof(ISettings.SearchWindowBackgroundAlpha)
176+
or nameof(ISettings.SearchWindowBackgroundBrightness)
177+
)
170178
{
171179
ScheduleApply();
172180
}
@@ -225,6 +233,8 @@ private void ApplyCustomLayers(Registration registration, FrameworkElement root,
225233
AddResource(registration, root, $"Themes/{profile}/Controls.xaml");
226234

227235
AddAccentColor(registration, root, systemTheme);
236+
237+
AddSearchWindowBackground(registration, root, systemTheme, profile);
228238
}
229239

230240
private static void AddWpfUiBase(Registration registration, FrameworkElement root, Theme theme)
@@ -271,11 +281,50 @@ private void AddAccentColor(Registration registration, FrameworkElement root, Th
271281
registration.AddedDictionaries.Add(resDict);
272282
}
273283

274-
private static SolidColorBrush GetBrush(Color color)
284+
private static SolidColorBrush GetBrush(Color color) =>
285+
ColorHelper.ToFrozenBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
286+
287+
private void AddSearchWindowBackground(
288+
Registration registration,
289+
FrameworkElement root,
290+
Theme systemTheme,
291+
string profile
292+
)
293+
{
294+
var brush = GetSearchWindowBackgroundBrush(systemTheme, profile);
295+
var resDict = new ResourceDictionary
296+
{
297+
["SearchWindowBackground"] = brush,
298+
["SearchResultsViewHeader"] = brush,
299+
};
300+
root.Resources.MergedDictionaries.Add(resDict);
301+
registration.AddedDictionaries.Add(resDict);
302+
}
303+
304+
private static readonly SolidColorBrush Win11LightBackgroundBrush = ColorHelper.ToFrozenBrush(System.Windows.Media.Color.FromArgb(0xE0, 0xF5, 0xF5, 0xF5));
305+
private static readonly SolidColorBrush Win10LightBackgroundBrush = ColorHelper.ToFrozenBrush(System.Windows.Media.Color.FromArgb(0xDD, 0xEE, 0xEE, 0xEE));
306+
private static readonly SolidColorBrush Win11DarkBackgroundBrush = ColorHelper.ToFrozenBrush(System.Windows.Media.Color.FromArgb(0xDA, 0x25, 0x25, 0x25));
307+
private static readonly SolidColorBrush Win10DarkBackgroundBrush = ColorHelper.ToFrozenBrush(System.Windows.Media.Color.FromArgb(0xF0, 0x25, 0x25, 0x25));
308+
309+
private SolidColorBrush GetSearchWindowBackgroundBrush(Theme systemTheme, string profile)
275310
{
276-
var brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
277-
brush.Freeze();
278-
return brush;
311+
if (string.Equals(_settings.SearchWindowBackground, "Custom", StringComparison.OrdinalIgnoreCase))
312+
{
313+
var color = ColorHelper.GetSearchWindowColor(
314+
_settings.SearchWindowBackgroundAlpha,
315+
_settings.SearchWindowBackgroundBrightness,
316+
systemTheme == Theme.Light
317+
);
318+
return ColorHelper.ToFrozenBrush(color);
319+
}
320+
321+
// Automatic
322+
if (systemTheme == Theme.Light)
323+
{
324+
return profile == "Win11" ? Win11LightBackgroundBrush : Win10LightBackgroundBrush;
325+
}
326+
327+
return profile == "Win11" ? Win11DarkBackgroundBrush : Win10DarkBackgroundBrush;
279328
}
280329

281330
public void Dispose()

0 commit comments

Comments
 (0)