Compare commits

..

2 Commits

Author SHA1 Message Date
Zhang Dian 7f557bb2c5 feat: update window decoration styles to use transparent backgrounds. 2026-05-21 15:14:24 +08:00
Zhang Dian ec94bdd36d Integrate font management for Linux demo (#822)
* feat: integrate font management by adding Semi.Avalonia.Demo.Fonts project.

* chore: test on ubuntu.

* feat: add linux options.

* feat: update theme settings and adjust window decorations.

* feat: add font to DRM project.

* misc: net8.0->net10.0
2026-05-18 21:16:03 +08:00
24 changed files with 113 additions and 97 deletions
+1
View File
@@ -3,6 +3,7 @@
<Project Path="demo/Semi.Avalonia.Demo.Android/Semi.Avalonia.Demo.Android.csproj"/>
<Project Path="demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj"/>
<Project Path="demo/Semi.Avalonia.Demo.Drm/Semi.Avalonia.Demo.Drm.csproj"/>
<Project Path="demo/Semi.Avalonia.Demo.Fonts/Semi.Avalonia.Demo.Fonts.csproj"/>
<Project Path="demo/Semi.Avalonia.Demo.Web/Semi.Avalonia.Demo.Web.csproj"/>
<Project Path="demo/Semi.Avalonia.Demo/Semi.Avalonia.Demo.csproj"/>
</Folder>
@@ -2,6 +2,7 @@
using Android.Runtime;
using Avalonia;
using Avalonia.Android;
using Semi.Avalonia.Demo.Fonts;
namespace Semi.Avalonia.Demo.Android;
@@ -1,16 +0,0 @@
using Avalonia;
using Avalonia.Media;
namespace Semi.Avalonia.Demo.Android;
public static class AvaloniaAppBuilderExtensions
{
private static string DefaultFontFamily => "avares://Semi.Avalonia.Demo.Android/Assets#Source Han Sans CN";
public static AppBuilder WithSourceHanSansCNFont(this AppBuilder builder) =>
builder.With(new FontManagerOptions
{
DefaultFamilyName = DefaultFontFamily,
FontFallbacks = [new FontFallback { FontFamily = new FontFamily(DefaultFontFamily) }]
});
}
@@ -21,7 +21,6 @@
<ItemGroup>
<AndroidResource Include="Icon.png" Link="Resources\drawable\Icon.png"/>
<AvaloniaResource Include="..\Fonts\*" Link="Assets\Fonts\%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
@@ -31,5 +30,6 @@
<ItemGroup>
<ProjectReference Include="..\Semi.Avalonia.Demo\Semi.Avalonia.Demo.csproj"/>
<ProjectReference Include="..\Semi.Avalonia.Demo.Fonts\Semi.Avalonia.Demo.Fonts.csproj"/>
</ItemGroup>
</Project>
+16 -10
View File
@@ -2,8 +2,10 @@
using Avalonia;
using Avalonia.Dialogs;
using Avalonia.Media;
using Semi.Avalonia.Demo.Fonts;
namespace Semi.Avalonia.Demo.Desktop;
#pragma warning disable CA1416, AVALONIA_X11_CSD, AVALONIA_X11_FORCE_CSD
sealed class Program
{
@@ -11,24 +13,28 @@ sealed class Program
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.With(new FontManagerOptions
public static void Main(string[] args)
{
FontFallbacks =
[
new FontFallback
var appBuilder = BuildAvaloniaApp();
if (!OperatingSystem.IsLinux())
appBuilder.With(new FontManagerOptions
{
FontFamily = new FontFamily("Microsoft YaHei")
FontFallbacks = [new FontFallback { FontFamily = new FontFamily("Microsoft YaHei") }]
});
appBuilder.StartWithClassicDesktopLifetime(args);
}
]
})
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
{
var appBuilder = AppBuilder.Configure<App>()
.UseManagedSystemDialogs()
.UsePlatformDetect()
.With(new Win32PlatformOptions())
.With(new X11PlatformOptions { EnableDrawnDecorations = true })
.LogToTrace();
if (OperatingSystem.IsLinux()) appBuilder.WithSourceHanSansCNFont();
return appBuilder;
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>..\Semi.Avalonia.Demo\Assets\irihi.ico</ApplicationIcon>
@@ -28,5 +28,6 @@
<ItemGroup>
<ProjectReference Include="..\Semi.Avalonia.Demo\Semi.Avalonia.Demo.csproj"/>
<ProjectReference Include="..\Semi.Avalonia.Demo.Fonts\Semi.Avalonia.Demo.Fonts.csproj"/>
</ItemGroup>
</Project>
+5 -3
View File
@@ -4,8 +4,10 @@ using System.Linq;
using System.Threading;
using Avalonia;
using Avalonia.Dialogs;
using Semi.Avalonia.Demo.Fonts;
namespace Semi.Avalonia.Demo.Drm;
#pragma warning disable CA1416, AVALONIA_X11_CSD, AVALONIA_X11_FORCE_CSD
sealed class Program
{
@@ -40,7 +42,8 @@ sealed class Program
=> AppBuilder.Configure<App>()
.UseManagedSystemDialogs()
.UsePlatformDetect()
.With(new Win32PlatformOptions())
.With(new X11PlatformOptions { EnableDrawnDecorations = true })
.WithSourceHanSansCNFont()
.LogToTrace();
private static void SilenceConsole()
@@ -50,7 +53,6 @@ sealed class Program
Console.CursorVisible = false;
while (true)
Console.ReadKey(true);
})
{ IsBackground = true }.Start();
}) { IsBackground = true }.Start();
}
}
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>..\Semi.Avalonia.Demo\Assets\irihi.ico</ApplicationIcon>
@@ -29,5 +29,6 @@
<ItemGroup>
<ProjectReference Include="..\Semi.Avalonia.Demo\Semi.Avalonia.Demo.csproj"/>
<ProjectReference Include="..\Semi.Avalonia.Demo.Fonts\Semi.Avalonia.Demo.Fonts.csproj"/>
</ItemGroup>
</Project>
@@ -0,0 +1,16 @@
using Avalonia;
using Avalonia.Media;
namespace Semi.Avalonia.Demo.Fonts;
public static class AvaloniaAppBuilderExtensions
{
public static AppBuilder WithSourceHanSansCNFont(this AppBuilder builder)
{
const string uri = "avares://Semi.Avalonia.Demo.Fonts/Assets#Source Han Sans CN";
return builder.With(new FontManagerOptions
{
DefaultFamilyName = uri, FontFallbacks = [new FontFallback { FontFamily = new FontFamily(uri) }]
});
}
}
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia"/>
</ItemGroup>
</Project>
@@ -1,16 +0,0 @@
using Avalonia;
using Avalonia.Media;
namespace Semi.Avalonia.Demo.Web;
public static class AvaloniaAppBuilderExtensions
{
private static string DefaultFontFamily => "avares://Semi.Avalonia.Demo.Web/Assets#Source Han Sans CN";
public static AppBuilder WithSourceHanSansCNFont(this AppBuilder builder) =>
builder.With(new FontManagerOptions
{
DefaultFamilyName = DefaultFontFamily,
FontFallbacks = [new FontFallback { FontFamily = new FontFamily(DefaultFontFamily) }]
});
}
+1
View File
@@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Browser;
using Semi.Avalonia.Demo.Fonts;
[assembly: SupportedOSPlatform("browser")]
@@ -6,15 +6,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="..\Fonts\*" Link="Assets\Fonts\%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Browser"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Semi.Avalonia.Demo\Semi.Avalonia.Demo.csproj"/>
<ProjectReference Include="..\Semi.Avalonia.Demo.Fonts\Semi.Avalonia.Demo.Fonts.csproj"/>
</ItemGroup>
</Project>
+1
View File
@@ -5,6 +5,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:semi="https://irihi.tech/semi"
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
RequestedThemeVariant="Default"
x:DataType="vm:ApplicationViewModel">
<Application.Styles>
<semi:SemiTheme Locale="zh-CN" />
+16 -12
View File
@@ -1,6 +1,6 @@
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Semi.Avalonia.Demo.ViewModels;
using Semi.Avalonia.Demo.Views;
@@ -15,22 +15,26 @@ public partial class App : Application
#if DEBUG
this.AttachDeveloperTools();
#endif
this.DataContext = new ApplicationViewModel();
DataContext = new ApplicationViewModel();
if (OperatingSystem.IsLinux())
{
Resources.Add("DefaultFontFamily", null);
}
}
public override void OnFrameworkInitializationCompleted()
{
switch (ApplicationLifetime)
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
case IClassicDesktopStyleApplicationLifetime desktop:
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
// BindingPlugins.DataValidators.RemoveAt(0);
desktop.MainWindow = new MainWindow();
break;
case ISingleViewApplicationLifetime singleView:
singleView.MainView = new MainView();
break;
desktop.MainWindow = new MainWindow { DataContext = new MainViewModel() };
}
else if (ApplicationLifetime is IActivityApplicationLifetime applicationLifetime)
{
applicationLifetime.MainViewFactory = () => new MainView { DataContext = new MainViewModel() };
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = new MainView { DataContext = new MainViewModel() };
}
this.RegisterFollowSystemTheme();
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
-5
View File
@@ -1,5 +0,0 @@
{
"sdk": {
"version": "8.0"
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.0",
"version": "10.0.0",
"rollForward": "latestMajor",
"allowPrerelease": true
}
@@ -46,8 +46,8 @@
<ControlTheme x:Key="{x:Type WindowDrawnDecorations}" TargetType="WindowDrawnDecorations">
<Setter Property="DefaultTitleBarHeight" Value="32" />
<Setter Property="DefaultFrameThickness" Value="1" />
<Setter Property="DefaultShadowThickness" Value="8" />
<Setter Property="DefaultFrameThickness" Value="4" />
<!-- <Setter Property="DefaultShadowThickness" Value="8" /> -->
<Setter Property="Template">
<WindowDrawnDecorationsTemplate>
<WindowDrawnDecorationsContent>
@@ -189,16 +189,16 @@
<!-- Hide caption buttons when the platform does not support the action -->
<Style Selector="^:not(:has-minimize) /template/ Button#PART_MinimizeButton">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^:not(:has-maximize) /template/ Button#PART_MaximizeButton">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^:not(:has-fullscreen) /template/ Button#PART_FullScreenButton">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
</Style>
<Style Selector="^:not(:has-fullscreen) /template/ Button#PART_PopoverFullScreenButton">
<Setter Property="IsVisible" Value="False"/>
<Setter Property="IsVisible" Value="False" />
</Style>
<!-- Fullscreen: hide overlay and titlebar (popover takes over) -->
@@ -1,6 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="WindowBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="WindowBorderBrush" ResourceKey="SemiColorBorder" />
<StaticResource x:Key="WindowBorderShadow" ResourceKey="SemiShadowElevated" />
<StaticResource x:Key="TitleBarBackground" ResourceKey="SemiColorBackground0" />
<SolidColorBrush x:Key="TitleBarBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="CaptionButtonPointeroverBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="CaptionButtonPressedBackground" ResourceKey="SemiColorFill2" />
@@ -1,5 +1,7 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StaticResource x:Key="TitleBarBackground" ResourceKey="SemiColorWindow" />
<SolidColorBrush x:Key="WindowBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="WindowBorderBrush" ResourceKey="SemiColorWindowText" />
<SolidColorBrush x:Key="TitleBarBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="CaptionButtonPointeroverBackground" ResourceKey="SemiColorHotlight" />
<StaticResource x:Key="CaptionButtonPressedBackground" ResourceKey="SemiColorHotlight" />
@@ -1,6 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="WindowBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="WindowBorderBrush" ResourceKey="SemiColorBorder" />
<StaticResource x:Key="WindowBorderShadow" ResourceKey="SemiShadowElevated" />
<StaticResource x:Key="TitleBarBackground" ResourceKey="SemiColorBackground0" />
<SolidColorBrush x:Key="TitleBarBackground">Transparent</SolidColorBrush>
<StaticResource x:Key="CaptionButtonPointeroverBackground" ResourceKey="SemiColorFill1" />
<StaticResource x:Key="CaptionButtonPressedBackground" ResourceKey="SemiColorFill2" />