mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +02:00
[Peek] Set button color on theme change (#26564)
* [WIP] Set button color manually * Remove unused aliases
This commit is contained in:
@@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using interop;
|
using interop;
|
||||||
|
using ManagedCommon;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
|
using Microsoft.UI;
|
||||||
using Microsoft.UI.Windowing;
|
using Microsoft.UI.Windowing;
|
||||||
using Microsoft.UI.Xaml;
|
|
||||||
using Microsoft.UI.Xaml.Input;
|
using Microsoft.UI.Xaml.Input;
|
||||||
using Peek.Common.Constants;
|
using Peek.Common.Constants;
|
||||||
using Peek.Common.Helpers;
|
|
||||||
using Peek.FilePreviewer.Models;
|
using Peek.FilePreviewer.Models;
|
||||||
using Peek.UI.Extensions;
|
using Peek.UI.Extensions;
|
||||||
using Peek.UI.Helpers;
|
using Peek.UI.Helpers;
|
||||||
@@ -23,15 +23,20 @@ namespace Peek.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An empty window that can be used on its own or navigated to within a Frame.
|
/// An empty window that can be used on its own or navigated to within a Frame.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed partial class MainWindow : WindowEx
|
public sealed partial class MainWindow : WindowEx, IDisposable
|
||||||
{
|
{
|
||||||
public MainWindowViewModel ViewModel { get; }
|
public MainWindowViewModel ViewModel { get; }
|
||||||
|
|
||||||
|
private ThemeListener themeListener;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.Activated += PeekWindow_Activated;
|
this.Activated += PeekWindow_Activated;
|
||||||
|
|
||||||
|
themeListener = new ThemeListener();
|
||||||
|
themeListener.ThemeChanged += (_) => HandleThemeChange();
|
||||||
|
|
||||||
ViewModel = App.GetService<MainWindowViewModel>();
|
ViewModel = App.GetService<MainWindowViewModel>();
|
||||||
|
|
||||||
NativeEventWaiter.WaitForEventLoop(Constants.ShowPeekEvent(), OnPeekHotkey);
|
NativeEventWaiter.WaitForEventLoop(Constants.ShowPeekEvent(), OnPeekHotkey);
|
||||||
@@ -41,6 +46,20 @@ namespace Peek.UI
|
|||||||
AppWindow.Closing += AppWindow_Closing;
|
AppWindow.Closing += AppWindow_Closing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleThemeChange()
|
||||||
|
{
|
||||||
|
AppWindow appWindow = this.GetAppWindow();
|
||||||
|
|
||||||
|
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
|
||||||
|
{
|
||||||
|
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void PeekWindow_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
|
private void PeekWindow_Activated(object sender, Microsoft.UI.Xaml.WindowActivatedEventArgs args)
|
||||||
{
|
{
|
||||||
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.Deactivated)
|
if (args.WindowActivationState == Microsoft.UI.Xaml.WindowActivationState.Deactivated)
|
||||||
@@ -203,5 +222,10 @@ namespace Peek.UI
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
themeListener?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,6 +226,14 @@ namespace Peek.UI.Views
|
|||||||
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
|
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
|
||||||
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
|
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
|
||||||
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
|
||||||
|
if (ThemeHelpers.GetAppTheme() == AppTheme.Light)
|
||||||
|
{
|
||||||
|
appWindow.TitleBar.ButtonForegroundColor = Colors.DarkSlateGray;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appWindow.TitleBar.ButtonForegroundColor = Colors.White;
|
||||||
|
}
|
||||||
|
|
||||||
mainWindow.SetTitleBar(this);
|
mainWindow.SetTitleBar(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user