コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
b01ea9159a |
検索条件に一致するファイルはありません
@@ -0,0 +1,8 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace ProxyForge.Interfaces;
|
||||
|
||||
internal interface IWindowThemeService
|
||||
{
|
||||
void Bind(Window window);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using ProxyForge.Core;
|
||||
using ProxyForge.Detection;
|
||||
using ProxyForge.Interfaces;
|
||||
using ProxyForge.Memory;
|
||||
using ProxyForge.Services;
|
||||
using ProxyForge.Settings;
|
||||
using ProxyForge.Streaming;
|
||||
using ProxyForge.ViewModels;
|
||||
@@ -60,6 +61,7 @@ internal sealed class PluginHost : IDisposable
|
||||
var chunkAllocator = new ChunkAllocator(65536);
|
||||
|
||||
MfSession.AddRef();
|
||||
WindowThemeRegistry.Register(new WindowThemeService());
|
||||
|
||||
IProxyEncoderFactory encoderFactory = new MfProxyEncoderFactory(
|
||||
budget,
|
||||
@@ -124,6 +126,7 @@ internal sealed class PluginHost : IDisposable
|
||||
{
|
||||
var vm = new GenerationPopupViewModel(CacheManager.ActiveGenerations);
|
||||
_popupView = new GenerationPopupView(vm);
|
||||
WindowThemeRegistry.Bind(_popupView);
|
||||
|
||||
var mainWindow = Application.Current?.MainWindow;
|
||||
if (mainWindow is { IsLoaded: true })
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using ProxyForge.Interfaces;
|
||||
using System.Windows;
|
||||
|
||||
namespace ProxyForge.Services;
|
||||
|
||||
internal static class WindowThemeRegistry
|
||||
{
|
||||
private static IWindowThemeService _service = NullWindowThemeService.Instance;
|
||||
|
||||
internal static void Register(IWindowThemeService service)
|
||||
=> Interlocked.Exchange(ref _service, service ?? NullWindowThemeService.Instance);
|
||||
|
||||
internal static void Bind(Window window)
|
||||
=> _service.Bind(window);
|
||||
|
||||
private sealed class NullWindowThemeService : IWindowThemeService
|
||||
{
|
||||
internal static readonly NullWindowThemeService Instance = new();
|
||||
private NullWindowThemeService() { }
|
||||
public void Bind(Window window) { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using ProxyForge.Interfaces;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ProxyForge.Services;
|
||||
|
||||
internal sealed class WindowThemeService : IWindowThemeService
|
||||
{
|
||||
public void Bind(Window window)
|
||||
{
|
||||
if (window is null) return;
|
||||
window.SourceInitialized += (_, _) => ApplyCurrentTheme(window);
|
||||
window.Loaded += (_, _) => ApplyCurrentTheme(window);
|
||||
}
|
||||
|
||||
private static void ApplyCurrentTheme(Window window)
|
||||
{
|
||||
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000)) return;
|
||||
var hwnd = new WindowInteropHelper(window).Handle;
|
||||
if (hwnd == nint.Zero) return;
|
||||
|
||||
var captionBrush = (window.TryFindResource(SystemColors.ControlBrushKey) as SolidColorBrush) ?? Brushes.White;
|
||||
var textBrush = (window.TryFindResource(SystemColors.WindowTextBrushKey) as SolidColorBrush) ?? Brushes.Black;
|
||||
|
||||
SetDwmColor(hwnd, NativeMethods.DwmwaCaption, captionBrush.Color);
|
||||
SetDwmColor(hwnd, NativeMethods.DwmwaBorder, captionBrush.Color);
|
||||
SetDwmColor(hwnd, NativeMethods.DwmwaText, textBrush.Color);
|
||||
}
|
||||
|
||||
private static void SetDwmColor(nint hwnd, uint attribute, Color color)
|
||||
{
|
||||
uint colorRef = color.R | ((uint)color.G << 8) | ((uint)color.B << 16);
|
||||
NativeMethods.DwmSetWindowAttribute(hwnd, attribute, ref colorRef, sizeof(uint));
|
||||
}
|
||||
|
||||
private static class NativeMethods
|
||||
{
|
||||
internal const uint DwmwaCaption = 35;
|
||||
internal const uint DwmwaBorder = 34;
|
||||
internal const uint DwmwaText = 36;
|
||||
|
||||
[DllImport("dwmapi.dll")]
|
||||
internal static extern int DwmSetWindowAttribute(nint hwnd, uint dwAttribute, ref uint pvAttribute, uint cbAttribute);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする