-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add WindowCornerHintsProperty #17354
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
using System; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace Avalonia.Platform; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Specifies hints for window corner appearance. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
[Flags] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
public enum Win32WindowCornerHints | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Default Avalonia behavior. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
NoHint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// The platform's default corner style. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
PlatformDefault, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+14
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the current behavior: Avalonia/src/Windows/Avalonia.Win32/WindowImpl.cs Lines 1150 to 1174 in 0bd90d8
So it is This is because DWMWCP_DEFAULT with client area extended results in not rounded corners. This is also why I've split the enum into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading, I think we need the following values: Default, Rounded, RoundedSmall, NotRounded (Alternative: Round, RoundSmall, DoNotRound following upstream API) |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Rounded corners for the window. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Rounded, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
/// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// Prevents corners from being rounded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
/// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
NotRounded | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,14 @@ namespace Avalonia.Controls | |
/// <summary> | ||
/// Set of Win32 specific properties and events that allow deeper customization of the application per platform. | ||
/// </summary> | ||
public static class Win32Properties | ||
public class Win32Properties | ||
{ | ||
public static readonly AttachedProperty<Win32WindowCornerHints> WindowCornerHintProperty = | ||
AvaloniaProperty.RegisterAttached<Win32Properties, Window, Win32WindowCornerHints>("WindowCornerHint"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we just make this a 3-state bool value? This property is ONLY controlling a window corner radius. This means we need to control whether it is ON or OFF. Then it's probably useful to have a "default" condition as well. bool? could communicate:
Will there ever be a reason to have more values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a windows specific property, as it is now, it should mirror windows API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point. That's the right way to look at it I think so your probably right. I also notice there are more values supported: https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference. Namely |
||
public static void SetWindowCornerHint(Window obj, Win32WindowCornerHints value) => obj.SetValue(WindowCornerHintProperty, value); | ||
public static Win32WindowCornerHints GetWindowCornerHint(Window obj) => obj.GetValue(WindowCornerHintProperty); | ||
|
||
public delegate (uint style, uint exStyle) CustomWindowStylesCallback(uint style, uint exStyle); | ||
public delegate IntPtr CustomWndProcHookCallback(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, ref bool handled); | ||
|
||
|
@@ -70,5 +76,16 @@ public static void RemoveWndProcHookCallback(TopLevel topLevel, CustomWndProcHoo | |
toplevelImpl.WndProcHookCallback -= callback; | ||
} | ||
} | ||
|
||
static Win32Properties() | ||
{ | ||
WindowCornerHintProperty.Changed.AddClassHandler<Window>((window, e) => | ||
{ | ||
if (window.PlatformImpl is IWin32OptionsTopLevelImpl toplevelImpl) | ||
{ | ||
toplevelImpl.SetWindowCornerHints(e.GetNewValue<Win32WindowCornerHints>()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this flags? And plural naming?
Reading the docs I don't think multiple values can be set at once. So it's isn't treated as flags.
https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_window_corner_preference
Perhaps the name should be
Win32WindowCornerPreference
as well. Although, I think it's supported only on Windows 11+ so calling it "Hints" might be appropriate as its ignored on platforms that don't support it.