From 2f5d4dad9acb56bf486b7d4098d26c5eb0aed452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Sat, 4 Oct 2025 13:40:35 +0200 Subject: [PATCH] Shell title bar buttons adjustments. --- .../Interfaces/INewThemeService.cs | 3 ++ Wino.Core.WinUI/Services/NewThemeService.cs | 35 +++++++++++- Wino.Mail.WinUI/ShellWindow.xaml.cs | 54 ++++++++++++++++++- 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Wino.Core.Domain/Interfaces/INewThemeService.cs b/Wino.Core.Domain/Interfaces/INewThemeService.cs index ab0f4651..d571d7ac 100644 --- a/Wino.Core.Domain/Interfaces/INewThemeService.cs +++ b/Wino.Core.Domain/Interfaces/INewThemeService.cs @@ -32,6 +32,9 @@ public interface INewThemeService : IInitializeAsync // Improved accent color management Task SetAccentColorAsync(string hexColor, bool preserveTheme = true); + // Title bar color management + void UpdateSystemCaptionButtonColors(); + // Backdrop management List GetAvailableBackdropTypes(); } diff --git a/Wino.Core.WinUI/Services/NewThemeService.cs b/Wino.Core.WinUI/Services/NewThemeService.cs index e4441cda..f430b3e6 100644 --- a/Wino.Core.WinUI/Services/NewThemeService.cs +++ b/Wino.Core.WinUI/Services/NewThemeService.cs @@ -13,6 +13,7 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Markup; using Microsoft.UI.Xaml.Media; using Windows.Storage; +using Windows.UI; using Windows.UI.ViewManagement; using Wino.Core.Domain; using Wino.Core.Domain.Enums; @@ -274,7 +275,39 @@ public class NewThemeService : INewThemeService { GetShellRootContent().DispatcherQueue.TryEnqueue(() => { - Debug.WriteLine("TODO: Updating caption button colors for NewThemeService"); + if (WinoApplication.MainWindow is not WindowEx mainWindow) return; + + var titleBar = mainWindow.AppWindow.TitleBar; + if (titleBar == null) return; + + // Determine if current theme is dark + bool isDarkTheme = _underlyingThemeService.IsUnderlyingThemeDark(); + + // Set button colors based on theme + // Background is always transparent for all buttons + titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + + if (isDarkTheme) + { + // Dark theme: use light text/icons for better contrast + titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White + titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white + titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White + titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white + } + else + { + // Light theme: use dark text/icons for better contrast + titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black + titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black + titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black + titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black + } + + Debug.WriteLine($"Updated title bar button colors for {(isDarkTheme ? "dark" : "light")} theme"); }); } diff --git a/Wino.Mail.WinUI/ShellWindow.xaml.cs b/Wino.Mail.WinUI/ShellWindow.xaml.cs index c188fcb0..c03fa2e7 100644 --- a/Wino.Mail.WinUI/ShellWindow.xaml.cs +++ b/Wino.Mail.WinUI/ShellWindow.xaml.cs @@ -3,17 +3,19 @@ using CommunityToolkit.Mvvm.Messaging; using Microsoft.Extensions.DependencyInjection; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Windows.UI; using Wino.Core.Domain.Interfaces; using Wino.Core.WinUI; using Wino.Core.WinUI.Interfaces; using Wino.Messaging.Client.Mails; +using Wino.Messaging.Client.Shell; using Wino.Messaging.UI; using Wino.Views; using WinUIEx; namespace Wino.Mail.WinUI; -public sealed partial class ShellWindow : WindowEx, IWinoShellWindow +public sealed partial class ShellWindow : WindowEx, IWinoShellWindow, IRecipient { public IStatePersistanceService StatePersistanceService { get; } = WinoApplication.Current.Services.GetService() ?? throw new Exception("StatePersistanceService not registered in DI container."); public IPreferencesService PreferencesService { get; } = WinoApplication.Current.Services.GetService() ?? throw new Exception("PreferencesService not registered in DI container."); @@ -21,6 +23,7 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow public ShellWindow() { WeakReferenceMessenger.Default.Register(this); + WeakReferenceMessenger.Default.Register(this); InitializeComponent(); @@ -32,6 +35,17 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow private void ConfigureTitleBar() { AppWindow.TitleBar.ExtendsContentIntoTitleBar = true; + + // Apply initial theme colors + var themeService = WinoApplication.Current.Services.GetService(); + if (themeService != null) + { + var underlyingThemeService = WinoApplication.Current.Services.GetService(); + if (underlyingThemeService != null) + { + UpdateTitleBarColors(underlyingThemeService.IsUnderlyingThemeDark()); + } + } } public void HandleAppActivation(LaunchActivatedEventArgs args) @@ -67,4 +81,42 @@ public sealed partial class ShellWindow : WindowEx, IWinoShellWindow ShellTitleBar.Content = shellPage.TopShellContent; } } + + public void Receive(ApplicationThemeChanged message) + { + UpdateTitleBarColors(message.IsUnderlyingThemeDark); + } + + private void UpdateTitleBarColors(bool isDarkTheme) + { + DispatcherQueue.TryEnqueue(() => + { + var titleBar = AppWindow.TitleBar; + if (titleBar == null) return; + + // Set button colors based on theme + // Background is always transparent for all buttons + titleBar.ButtonBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonInactiveBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonHoverBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + titleBar.ButtonPressedBackgroundColor = Color.FromArgb(0, 0, 0, 0); // Transparent + + if (isDarkTheme) + { + // Dark theme: use light text/icons for better contrast + titleBar.ButtonForegroundColor = Color.FromArgb(255, 255, 255, 255); // White + titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 255, 255, 255); // Semi-transparent white + titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 255, 255, 255); // White + titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 255, 255, 255); // Slightly dimmed white + } + else + { + // Light theme: use dark text/icons for better contrast + titleBar.ButtonForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black + titleBar.ButtonInactiveForegroundColor = Color.FromArgb(128, 0, 0, 0); // Semi-transparent black + titleBar.ButtonHoverForegroundColor = Color.FromArgb(255, 0, 0, 0); // Black + titleBar.ButtonPressedForegroundColor = Color.FromArgb(200, 0, 0, 0); // Slightly dimmed black + } + }); + } }