-
-
Notifications
You must be signed in to change notification settings - Fork 897
Add setting border color + fix background extending inside FluentWindow #1508
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
Open
Nuklon
wants to merge
8
commits into
lepoco:main
Choose a base branch
from
Nuklon:patch-22
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
32467e1
Add setting border color
Nuklon 957eb0a
Update FluentWindow.cs
Nuklon b697a68
Update FluentWindow.cs
Nuklon 22b84f7
Update UnsafeNativeMethods.cs
Nuklon 52cf5ba
Use border only when active, similar to WinUI
Nuklon b9bb8cf
Update UnsafeNativeMethods.cs
Nuklon e1a5f34
Listen for theme changes
Nuklon 90f9231
Ensure desktop composition is enabled before changing WindowChrome
Nuklon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -49,15 +49,64 @@ public static bool ApplyWindowCornerPreference(IntPtr handle, WindowCornerPrefer | |
|
||
int pvAttribute = (int)UnsafeReflection.Cast(cornerPreference); | ||
|
||
// TODO: Validate HRESULT | ||
_ = Dwmapi.DwmSetWindowAttribute( | ||
return Dwmapi.DwmSetWindowAttribute( | ||
handle, | ||
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, | ||
ref pvAttribute, | ||
Marshal.SizeOf(typeof(int)) | ||
); | ||
) == 0; | ||
} | ||
|
||
return true; | ||
/// <summary> | ||
/// Tries to apply the color of the border. | ||
/// </summary> | ||
/// <param name="window">The window.</param> | ||
/// <param name="color">The color.</param> | ||
/// <returns><see langword="true" /> if invocation of native Windows function succeeds.</returns> | ||
public static bool ApplyBorderColor(Window window, Color color) => | ||
GetHandle(window, out IntPtr windowHandle) | ||
&& ApplyBorderColor(windowHandle, color); | ||
|
||
/// <summary> | ||
/// Tries to apply the color of the border. | ||
/// </summary> | ||
/// <param name="window">The window.</param> | ||
/// <param name="color">The color.</param> | ||
/// <returns><see langword="true" /> if invocation of native Windows function succeeds.</returns> | ||
public static bool ApplyBorderColor(Window window, int color) => | ||
GetHandle(window, out IntPtr windowHandle) | ||
&& ApplyBorderColor(windowHandle, color); | ||
|
||
/// <summary> | ||
/// Tries to apply the color of the border. | ||
/// </summary> | ||
/// <param name="handle">The handle.</param> | ||
/// <param name="color">The color.</param> | ||
/// <returns><see langword="true"/> if invocation of native Windows function succeeds.</returns> | ||
public static bool ApplyBorderColor(IntPtr handle, Color color) | ||
{ | ||
return ApplyBorderColor(handle, (color.B << 16) | (color.G << 8) | color.R); | ||
} | ||
|
||
/// <summary> | ||
/// Tries to apply the color of the border. | ||
/// </summary> | ||
/// <param name="handle">The handle.</param> | ||
/// <param name="color">The color.</param> | ||
/// <returns><see langword="true"/> if invocation of native Windows function succeeds.</returns> | ||
public static bool ApplyBorderColor(IntPtr handle, int color) | ||
{ | ||
if (handle == IntPtr.Zero) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!User32.IsWindow(handle)) | ||
{ | ||
return false; | ||
} | ||
|
||
return Dwmapi.DwmSetWindowAttribute(handle, Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, ref color, sizeof(int)) == 0; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -93,10 +142,7 @@ public static bool RemoveWindowDarkMode(IntPtr handle) | |
dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DMWA_USE_IMMERSIVE_DARK_MODE_OLD; | ||
} | ||
|
||
// TODO: Validate HRESULT | ||
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. I also corrected this, it's only returning 0 on success. |
||
_ = Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); | ||
|
||
return true; | ||
return Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))) == 0; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -132,10 +178,7 @@ public static bool ApplyWindowDarkMode(IntPtr handle) | |
dwAttribute = Dwmapi.DWMWINDOWATTRIBUTE.DMWA_USE_IMMERSIVE_DARK_MODE_OLD; | ||
} | ||
|
||
// TODO: Validate HRESULT | ||
_ = Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))); | ||
|
||
return true; | ||
return Dwmapi.DwmSetWindowAttribute(handle, dwAttribute, ref pvAttribute, Marshal.SizeOf(typeof(int))) == 0; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -214,15 +257,12 @@ public static bool ApplyWindowBackdrop(IntPtr handle, WindowBackdropType backgro | |
return false; | ||
} | ||
|
||
// TODO: Validate HRESULT | ||
_ = Dwmapi.DwmSetWindowAttribute( | ||
return Dwmapi.DwmSetWindowAttribute( | ||
handle, | ||
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, | ||
ref backdropPvAttribute, | ||
Marshal.SizeOf(typeof(int)) | ||
); | ||
|
||
return true; | ||
) == 0; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -296,15 +336,12 @@ public static bool ApplyWindowLegacyMicaEffect(IntPtr handle) | |
{ | ||
var backdropPvAttribute = 0x1; // Enable | ||
|
||
// TODO: Validate HRESULT | ||
_ = Dwmapi.DwmSetWindowAttribute( | ||
return Dwmapi.DwmSetWindowAttribute( | ||
handle, | ||
Dwmapi.DWMWINDOWATTRIBUTE.DWMWA_MICA_EFFECT, | ||
ref backdropPvAttribute, | ||
Marshal.SizeOf(typeof(int)) | ||
); | ||
|
||
return true; | ||
) == 0; | ||
} | ||
|
||
/// <summary> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the fix for FluentWindow. -1 cannot be used if None is specified, otherwise the background of the window is rendered 1 pixel inside, which is obviously wrong.