[QuickAccent]Theming support (#22446)

* Adding theme awereness

* Adding theming colors

* High contrast

* Downgrade ModernWPF package

* Adding ModernWPF and PowerToys.Common.UI to installer

* Removing unused file and MahApps

* Removed MahApps from installer string

* fix projects and setup

* removed PowerAccent

* addressed PR feedback

Co-authored-by: Davide <25966642+davidegiacometti@users.noreply.github.com>
This commit is contained in:
Niels Laute
2022-12-09 21:40:00 +01:00
committed by GitHub
parent e5d001e434
commit b6a905709a
18 changed files with 312 additions and 176 deletions

View File

@@ -1,17 +1,18 @@
<Application x:Class="PowerAccent.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PowerAccent"
StartupUri="Selector.xaml">
<Application
x:Class="PowerAccent.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PowerAccent"
xmlns:ui="http://schemas.modernwpf.com/2019"
StartupUri="Selector.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Theme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
<ui:ThemeResources />
<ui:XamlControlsResources />
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
</Application>

View File

@@ -1,32 +1,64 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
using System.Windows;
using Common.UI;
using PowerAccent.Core.Tools;
namespace PowerAccent.UI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : Application, IDisposable
{
private static Mutex _mutex;
private bool _disposed;
private ThemeManager _themeManager;
protected override void OnStartup(StartupEventArgs e)
{
const string appName = "QuickAccent";
_mutex = new Mutex(true, appName, out bool createdNew);
_mutex = new Mutex(true, "QuickAccent", out bool createdNew);
if (!createdNew)
{
// app is already running! Exiting the application
Logger.LogWarning("Another running QuickAccent instance was detected. Exiting QuickAccent");
Application.Current.Shutdown();
}
_themeManager = new ThemeManager(this);
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
_mutex?.ReleaseMutex();
base.OnExit(e);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
if (disposing)
{
_mutex?.Dispose();
_themeManager?.Dispose();
}
_disposed = true;
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

View File

@@ -7,25 +7,24 @@
<Nullable>disable</Nullable>
<UseWPF>true</UseWPF>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<ApplicationIcon>a-icon.ico</ApplicationIcon>
<AssemblyName>PowerAccent</AssemblyName>
<ApplicationIcon>icon.ico</ApplicationIcon>
<AssemblyName>PowerToys.PowerAccent</AssemblyName>
<XamlDebuggingInformation>True</XamlDebuggingInformation>
<StartupObject>PowerAccent.UI.Program</StartupObject>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\modules\PowerAccent</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<ItemGroup>
<None Remove="win11desktop.jpg" />
</ItemGroup>
<ItemGroup>
<Resource Include="a-icon.ico">
<Resource Include="icon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="win11desktop.jpg" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
</ItemGroup>
<ItemGroup>
@@ -33,7 +32,4 @@
<ProjectReference Include="..\PowerAccent.Core\PowerAccent.Core.csproj" />
<ProjectReference Include="..\PowerAccentKeyboardService\PowerAccentKeyboardService.vcxproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma warning disable SA1310 // FieldNamesMustNotContainUnderscore
using System;
using System.Diagnostics;
@@ -11,43 +10,31 @@ using System.Windows;
using interop;
using ManagedCommon;
using PowerAccent.Core.Tools;
using PowerAccent.UI;
namespace PowerAccent;
namespace PowerAccent.UI;
internal static class Program
{
private static readonly CancellationTokenSource _tokenSource = new ();
private const string PROGRAM_NAME = "QuickAccent";
private const string PROGRAM_APP_NAME = "PowerToys.PowerAccent";
private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource();
private static App _application;
private static int _powerToysRunnerPid;
[STAThread]
public static void Main(string[] args)
{
_ = new Mutex(true, PROGRAM_APP_NAME, out bool instantiated);
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredQuickAccentEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
{
Logger.LogWarning("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
return;
}
if (instantiated)
{
Arguments(args);
Arguments(args);
InitEvents();
InitEvents();
_application = new App();
_application.InitializeComponent();
_application.Run();
}
else
{
Logger.LogWarning("Another running QuickAccent instance was detected. Exiting QuickAccent");
}
_application = new App();
_application.InitializeComponent();
_application.Run();
}
private static void InitEvents()
@@ -55,7 +42,7 @@ internal static class Program
Task.Run(
() =>
{
EventWaitHandle eventHandle = new (false, EventResetMode.AutoReset, Constants.PowerAccentExitEvent());
EventWaitHandle eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.PowerAccentExitEvent());
if (eventHandle.WaitOne())
{
Terminate();
@@ -69,15 +56,16 @@ internal static class Program
{
try
{
_ = int.TryParse(args[0], out _powerToysRunnerPid);
Logger.LogInfo($"QuickAccent started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}");
RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
if (int.TryParse(args[0], out _powerToysRunnerPid))
{
Logger.LogInfo("PowerToys Runner exited. Exiting QuickAccent");
Terminate();
});
Logger.LogInfo($"QuickAccent started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}");
RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () =>
{
Logger.LogInfo("PowerToys Runner exited. Exiting QuickAccent");
Terminate();
});
}
}
catch (Exception ex)
{

View File

@@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PowerAccent.UI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
Title="MainWindow"
Height="120"
MinWidth="600"
@@ -23,6 +24,7 @@
<TextBlock
VerticalAlignment="Center"
FontSize="18"
Foreground="{DynamicResource PrimaryForegroundBrush}"
Text="{Binding}"
TextAlignment="Center" />
</DataTemplate>
@@ -42,8 +44,8 @@
<Border
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="#F9F9F9"
BorderBrush="#B6B6B6"
Background="{DynamicResource SecondaryBackgroundBrush}"
BorderBrush="{DynamicResource WindowsBorderBrush}"
BorderThickness="1"
CornerRadius="8">
<Border.Effect>
@@ -57,82 +59,72 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox
x:Name="characters"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Background="Transparent"
IsHitTestVisible="False"
HorizontalAlignment="Center">
<ListBox.ItemContainerStyle>
<Style
TargetType="ListBoxItem">
<Setter Property="ContentTemplate" Value="{StaticResource DefaultKeyTemplate}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid
Width="48"
Height="48"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SnapsToDevicePixels="true"
Style="{DynamicResource borderContent}">
<Rectangle
x:Name="SelectionIndicator"
Margin="7"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="#005FB8"
RadiusX="4"
RadiusY="4"
Visibility="Collapsed" />
<ContentPresenter Margin="12" />
<Border Background="{DynamicResource PrimaryBackgroundBrush}" CornerRadius="8">
<ListBox
x:Name="characters"
HorizontalAlignment="Center"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Background="Transparent"
IsHitTestVisible="False">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="ContentTemplate" Value="{StaticResource DefaultKeyTemplate}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid
Width="48"
Height="48"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SnapsToDevicePixels="true"
Style="{DynamicResource borderContent}">
<Rectangle
x:Name="SelectionIndicator"
Margin="7"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="{DynamicResource SystemControlBackgroundAccentBrush}"
RadiusX="4"
RadiusY="4"
Visibility="Collapsed" />
<ContentPresenter Margin="12" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="SelectionIndicator" Property="Visibility" Value="Visible" />
<Setter Property="ContentTemplate" Value="{StaticResource SelectedKeyTemplate}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
IsItemsHost="False"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="SelectionIndicator" Property="Visibility" Value="Visible" />
<Setter Property="ContentTemplate" Value="{StaticResource SelectedKeyTemplate}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="False" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Border>
</ListBox>
<Grid
Grid.Row="1"
Visibility="{Binding CharacterNameVisibility, UpdateSourceTrigger=PropertyChanged}">
<Border
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="#F3F3F3"
CornerRadius="0,0,8,8">
<TextBlock
x:Name="characterName"
Margin="8"
FontSize="12"
Foreground="#8D8D8D"
Text="(U+0000) A COOL LETTER NAME COMES HERE"
TextAlignment="Center" />
</Border>
<Grid Grid.Row="1" Visibility="{Binding CharacterNameVisibility, UpdateSourceTrigger=PropertyChanged}">
<TextBlock
x:Name="characterName"
Margin="8"
FontSize="12"
Foreground="{DynamicResource SecondaryForegroundBrush}"
Text="(U+0000) A COOL LETTER NAME COMES HERE"
TextAlignment="Center" />
<Rectangle
Height="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Fill="#E5E5E5" />
Fill="{DynamicResource DividerBorderBrush}" />
</Grid>
</Grid>
</Border>

View File

@@ -0,0 +1,32 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">Dark.Accent1</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent1 (Dark)</system:String>
<system:String x:Key="Theme.BaseColorScheme">Dark</system:String>
<system:String x:Key="Theme.ColorScheme">Accent1</system:String>
<Color x:Key="Theme.PrimaryAccentColor">Black</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush
x:Key="WindowBorderBrush"
Opacity="0.4"
Color="#FF757575" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFFFFFFF" />
<SolidColorBrush
x:Key="SecondaryForegroundBrush"
Opacity="0.5442"
Color="#FFFFFFFF" />
</ResourceDictionary>

View File

@@ -0,0 +1,26 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent2</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent2 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent2</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FFffff00" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFffff00" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF00ff00" />
</ResourceDictionary>

View File

@@ -0,0 +1,26 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent3</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent3 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent3</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FF00ff00" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FF00ff00" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FFc0c0c0" />
</ResourceDictionary>

View File

@@ -0,0 +1,26 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent4</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent4 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent4</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FFffffff" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFffffff" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF1aebff" />
</ResourceDictionary>

View File

@@ -0,0 +1,26 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent5</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent5 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent5</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FFEEEEEE" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.25"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FF000000" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0578"
Color="#FF000000" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FF000000" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF37006e" />
</ResourceDictionary>

View File

@@ -0,0 +1,35 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">Light.Accent1</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent1 (Light)</system:String>
<system:String x:Key="Theme.BaseColorScheme">Light</system:String>
<system:String x:Key="Theme.ColorScheme">Accent1</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FFEEEEEE" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.25"
Color="#FFFFFFFF" />
<SolidColorBrush
x:Key="WindowBorderBrush"
Opacity="0.4"
Color="#FF757575" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0578"
Color="#FF000000" />
<SolidColorBrush
x:Key="PrimaryForegroundBrush"
Opacity="0.8956"
Color="#FF000000" />
<SolidColorBrush
x:Key="SecondaryForegroundBrush"
Opacity="0.6189"
Color="#FF000000" />
</ResourceDictionary>

View File

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -1,27 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\Version.props" />
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<UseWPF>true</UseWPF>
<Nullable>disable</Nullable>
<StartupObject>PowerAccent.Program</StartupObject>
<OutputPath>$(SolutionDir)$(Platform)\$(Configuration)\modules\PowerAccent</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<AssemblyName>PowerToys.PowerAccent</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
<ProjectReference Include="..\PowerAccent.UI\PowerAccent.UI.csproj" />
</ItemGroup>
</Project>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB