Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theming for powertoys run #4007

Merged
merged 9 commits into from
Jun 5, 2020
3 changes: 1 addition & 2 deletions src/modules/launcher/PowerLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void OnStartup(object sender, StartupEventArgs e)
StringMatcher.Instance = _stringMatcher;
_stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;

ThemeManager themeManager = new ThemeManager(this);
PluginManager.LoadPlugins(_settings.PluginSettings);
_mainVM = new MainViewModel(_settings);
var window = new MainWindow(_settings, _mainVM);
Expand All @@ -83,8 +84,6 @@ private void OnStartup(object sender, StartupEventArgs e)
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);

// main windows needs initialized before theme change because of blur settings
ThemeManager.Instance.Settings = _settings;
ThemeManager.Instance.ChangeTheme(_settings.Theme);

Http.Proxy = _settings.Proxy;

Expand Down
20 changes: 3 additions & 17 deletions src/modules/launcher/PowerLauncher/LauncherControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,11 @@
d:DesignHeight="300"
d:DesignWidth="720">
<UserControl.Resources>
<Color x:Key="SystemBaseMediumLowColor">#66000000</Color>
<SolidColorBrush x:Key="TextControlPlaceholderForeground" Color="#66000000" />
<SolidColorBrush x:Key="TextBox.Static.Border" Color="Transparent"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="Transparent"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="Transparent"/>

<!--
https://github.com/MicrosoftDocs/windows-uwp/issues/2072
TextControlPlaceholderForeground is based on SystemBaseMediumLowColor
Light=#66000000
Dark=#66FFFFFF
Highcontrast
should be based from SystemColors https://docs.microsoft.com/en-us/archive/blogs/wpf/systemcolors-reference
-->

<Style x:Key="QueryTextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource ControlTextBrushKey}"/>
<Setter Property="CaretBrush" Value="{DynamicResource ControlTextBrushKey}"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
Expand Down Expand Up @@ -75,7 +61,7 @@
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
<Setter Property="SelectionBrush" Value="{DynamicResource InactiveSelectionHighlightBrushKey}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
Expand Down
6 changes: 0 additions & 6 deletions src/modules/launcher/PowerLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
d:DataContext="{d:DesignInstance vm:MainViewModel}">
<Window.Resources>
<SolidColorBrush x:Key="SystemChromeLow" Color="#FFF2F2F2" />
<!--"key": "SystemChromeLowColor",
"name": "ChromeLow",
"lightHex": "#FFF2F2F2",
"darkHex": "#FF171717"-->

<CubicEase x:Key="CubicEaseOut" EasingMode="EaseOut"/>

<!-- Some of the durations are different to give a 'parallax' feel (like start menu has as well) -->
Expand Down
16 changes: 12 additions & 4 deletions src/modules/launcher/PowerLauncher/PowerLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
<ItemGroup>
<Page Include="App.xaml" />
</ItemGroup>

<ItemGroup>
<Page Remove="Themes\ThemeBuilder\Template.xaml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Fody" Version="6.1.1">
Expand Down Expand Up @@ -189,4 +185,16 @@
</None>
</ItemGroup>

<ItemGroup>
<Page Update="Themes\HighContrast.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Themes\Dark.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Themes\Light.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>

</Project>
29 changes: 3 additions & 26 deletions src/modules/launcher/PowerLauncher/ResultList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,20 @@
<ResourceDictionary Source="pack://application:,,,/Styles/UWPScrollBarStyle.xaml" />
</ResourceDictionary.MergedDictionaries>-->


<!-- These colors are based on the UWP XAML resources -->

<!-- Dark theme (a.k.a. "Default") -->
<!--<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#30FFFFFF" />
<SolidColorBrush x:Key="ButtonBorderPointerOver" Color="#61FFFFFF" />
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="#30FFFFFF" />
<SolidColorBrush x:Key="ButtonBorderPressed" Color="#61FFFFFF" />
<SolidColorBrush x:Key="ListViewItemBackgroundPointerOver" Color="#FFFFFFFF" />-->

<!-- Light theme -->
<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#2E000000" />
<SolidColorBrush x:Key="ButtonBorderPointerOver" Color="#61000000" />
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="#33000000" />
<SolidColorBrush x:Key="ButtonBorderPressed" Color="#61000000" />
<SolidColorBrush x:Key="ListViewItemBackgroundPointerOver" Color="#FF000000" />

<!-- High contrast -->
<!--<SolidColorBrush x:Key="ButtonBackgroundPointerOver" Color="#33FFFFFF" />
<SolidColorBrush x:Key="ButtonBorderPointerOver" Color="#66FFFFFF" />
<SolidColorBrush x:Key="ButtonBackgroundPressed" Color="#33FFFFFF" />
<SolidColorBrush x:Key="ButtonBorderPressed" Color="#66FFFFFF" />-->


<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<Style x:Key="FocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" StrokeDashArray="1 2" SnapsToDevicePixels="true" StrokeThickness="1" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Rectangle Margin="2" StrokeDashArray="1 2" SnapsToDevicePixels="true" StrokeThickness="1" Stroke="{DynamicResource ControlTextBrushKey}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="IconButtonStyle" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource ControlTextBrushKey}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
Expand Down Expand Up @@ -89,6 +65,7 @@

<Style x:Key="ResultsListViewItemContainerStyle" TargetType="ListViewItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource ControlTextBrushKey}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
Expand Down
94 changes: 94 additions & 0 deletions src/modules/launcher/PowerLauncher/ThemeManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using ControlzEx.Theming;
using MahApps.Metro.Theming;
using System;
using System.Diagnostics;
using System.Windows;

namespace Wox.Core.Resource
{
public class ThemeManager
{
private Theme currentTheme;
private readonly Application App;
private readonly string LightTheme = "Light.Accent1";
private readonly string DarkTheme = "Dark.Accent1";
private readonly string HighContrastTheme = "HighContrast.Accent2";

public ThemeManager(Application app)
{
this.App = app;

Uri HighContrastThemeUri = new Uri("pack://application:,,,/Themes/HighContrast.xaml");
Uri LightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml");
Uri DarkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml");

ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(HighContrastThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(LightThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
new LibraryTheme(DarkThemeUri,
MahAppsLibraryThemeProvider.DefaultInstance));

ResetTheme();
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged;
SystemParameters.StaticPropertyChanged += (sender, args) =>
{
if (args.PropertyName == nameof(SystemParameters.HighContrast))
{
ResetTheme();
}
};
}

public void ResetTheme()
{
if (SystemParameters.HighContrast)
{
ChangeTheme(Theme.HighContrast);
}
else
{
string baseColor = WindowsThemeHelper.GetWindowsBaseColor();
ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor));
}
}

private void ChangeTheme(Theme theme)
{
if (theme == currentTheme)
return;
if (theme == Theme.HighContrast)
{
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.HighContrastTheme);
currentTheme = Theme.HighContrast;
}
else if (theme == Theme.Light)
{
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.LightTheme);
currentTheme = Theme.Light;
}
else if (theme == Theme.Dark)
{
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(this.App, this.DarkTheme);
currentTheme = Theme.Dark;
}
}

private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e)
{
ResetTheme();
}
}

enum Theme
{
None,
Light,
Dark,
HighContrast
}
}
141 changes: 0 additions & 141 deletions src/modules/launcher/PowerLauncher/Themes/Base.xaml

This file was deleted.

This file was deleted.

Loading