Browse Source
* [X11] Allow setting WM_CLASS and _NET_WM_WINDOW_TYPE * Renamed to X11Properties and moved to Avalonia.Controls * [PrivateApi] * Rename * Suggested doc Co-authored-by: Max Katz <maxkatz6@outlook.com> --------- Co-authored-by: Max Katz <maxkatz6@outlook.com>pull/14782/head
committed by
GitHub
3 changed files with 94 additions and 4 deletions
@ -0,0 +1,21 @@ |
|||||
|
using Avalonia.Metadata; |
||||
|
namespace Avalonia.Controls.Platform; |
||||
|
|
||||
|
public enum X11NetWmWindowType |
||||
|
{ |
||||
|
Normal, |
||||
|
Dialog, |
||||
|
Utility, |
||||
|
Menu, |
||||
|
Toolbar, |
||||
|
Splash, |
||||
|
Dock, |
||||
|
Desktop |
||||
|
} |
||||
|
|
||||
|
[PrivateApi] |
||||
|
public interface IX11OptionsToplevelImplFeature |
||||
|
{ |
||||
|
void SetNetWmWindowType(X11NetWmWindowType type); |
||||
|
void SetWmClass(string? className); |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using Avalonia.Controls.Platform; |
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Reactive; |
||||
|
|
||||
|
namespace Avalonia.Controls; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Set of X11 specific properties and events that allow deeper customization of the application per platform.
|
||||
|
/// </summary>
|
||||
|
public class X11Properties |
||||
|
{ |
||||
|
public static readonly AttachedProperty<X11NetWmWindowType> NetWmWindowTypeProperty = |
||||
|
AvaloniaProperty.RegisterAttached<X11Properties, Window, X11NetWmWindowType>("NetWmWindowType"); |
||||
|
|
||||
|
public static void SetNetWmWindowType(Window obj, X11NetWmWindowType value) => obj.SetValue(NetWmWindowTypeProperty, value); |
||||
|
public static X11NetWmWindowType GetNetWmWindowType(Window obj) => obj.GetValue(NetWmWindowTypeProperty); |
||||
|
|
||||
|
public static readonly AttachedProperty<string?> WmClassProperty = |
||||
|
AvaloniaProperty.RegisterAttached<X11Properties, Window, string?>("WmClass"); |
||||
|
|
||||
|
public static void SetWmClass(Window obj, string? value) => obj.SetValue(WmClassProperty, value); |
||||
|
public static string? GetWmClass(Window obj) => obj.GetValue(WmClassProperty); |
||||
|
|
||||
|
static X11Properties() |
||||
|
{ |
||||
|
NetWmWindowTypeProperty.Changed.Subscribe(OnNetWmWindowTypeChanged); |
||||
|
WmClassProperty.Changed.Subscribe(OnWmClassChanged); |
||||
|
} |
||||
|
|
||||
|
private static IX11OptionsToplevelImplFeature? TryGetFeature(AvaloniaPropertyChangedEventArgs e) |
||||
|
=> (e.Sender as TopLevel)?.PlatformImpl?.TryGetFeature<IX11OptionsToplevelImplFeature>(); |
||||
|
|
||||
|
private static void OnWmClassChanged(AvaloniaPropertyChangedEventArgs<string?> e) => |
||||
|
TryGetFeature(e)?.SetWmClass(e.NewValue.GetValueOrDefault(null)); |
||||
|
|
||||
|
private static void OnNetWmWindowTypeChanged(AvaloniaPropertyChangedEventArgs<X11NetWmWindowType> e) => |
||||
|
TryGetFeature(e)?.SetNetWmWindowType(e.NewValue.GetValueOrDefault()); |
||||
|
} |
||||
Loading…
Reference in new issue