-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[X11] Allow setting WM_CLASS and _NET_WM_WINDOW_TYPE (#14619)
* [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 <[email protected]> --------- Co-authored-by: Max Katz <[email protected]>
- Loading branch information
Showing
3 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Avalonia.Controls/Platform/IX11OptionsToplevelImplFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters