Skip to content
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

Using ExtendClientAreaToDecorationsHint disables window shadow on Windows #9989

Open
MinikPLayer opened this issue Jan 16, 2023 · 20 comments
Open

Comments

@MinikPLayer
Copy link
Contributor

Describe the bug
When using "ExtendClientAreaToDecorationsHint=True" on Avalonia 11.0.0-preview1 or later, app window doesn't have a shadow and looks very "flat".

To Reproduce

  1. Create a new Avalonia project using 11.0.0-preview version
  2. Add "ExtendClientAreaToDecorationsHint=True" to the MainWindow.axaml
  3. Window won't have a shadow
  4. Switch to avalonia version 0.10.18
  5. Window will have a shadow

Expected behavior
Window having a shadow even when using "ExtendClientAreaToDecorationsHint"

Screenshots
noShadow_11.0.0-preview
shadow-0.10.18

Desktop (please complete the following information):

  • OS: Windows 10 22H2
  • Version: 11.0.0-preview4

Additional context

@MinikPLayer MinikPLayer changed the title With 11.0.0-preview, using ExtendClientAreaToDecorationsHint disables window shadow on Windows Using ExtendClientAreaToDecorationsHint disables window shadow on Windows Jan 16, 2023
@navhaxs
Copy link

navhaxs commented Feb 5, 2023

I did some digging and found that this is a regression caused by #8393

Current behaviour on master
image

If I revert the changes from the PR, then the drop shadow comes back
image

i.e. change var defaultMargin = _isUsingComposition ? 0 : 1; to var defaultMargin = 1;

@batzen
Copy link

batzen commented Feb 6, 2023

@Tetedeiench @maxkatz6 If you want to solve the flickering/white area appearing while resizing and white window flashing during window show I could give some tips on how to solve those issues, as i also had to solve them in the custom window chrome code in ControlzEx.
ControlzEx is for WPF but the underlying issues should be the same, i guess.
Just ping me if you are interested.

@Tetedeiench
Copy link
Contributor

@batzen I think we are all interested in a better fix - my PR fixed the window background turning white when resizing, but it has implications way beyond the fix and probably should be questioned af of now.

Now, I'm a huge newbie when it comes to such topics, and I just happened to stumble upon something that might have done the trick, but ultimately wasn't satisfying. I'm not sure I'm qualified to fix this with my current capabilities in Win32 topics !

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 8, 2023

@batzen @Tetedeiench @navhaxs indeed windowing backend on win32 needs some cleanup. Especially when it first was written before WinUI compositor was used, and had to be patched in multiple places (including #8393) to get it work better with composition.

@Tetedeiench
Copy link
Contributor

@maxkatz6 This would be nice but quite the ordeal.

Perhaps we can initially rely on the kind offer from @batzen to give us a better fix for the white background resize issue while keeping the 1px margin which seems to be important for... reasons ?

@vdm97
Copy link

vdm97 commented May 9, 2023

Hi, what is the status on this issue? The corresponding issues were all closed as not planned. Does this mean that this issue will be fixed after the release of version 11 in e.g. version 11.1 or 11.2, etc?

@navhaxs
Copy link

navhaxs commented May 9, 2023

I would suggest that #8393 be reverted in the meantime until a better solution can be found. Because unfortunately the PR does break the expected behaviour here :( :(

I don't think it would be good for window shadows to be broken with ExtendClientAreaToDecorationsHint=True in the first stable release of 11.0, particularly since window shadows is currently working for today's Avalonia versions. I see there have already been a number of duplicate issues on this :(

Isn't win32 ticky...

@Tetedeiench
Copy link
Contributor

Well, either you suffer from a big white flash when resizing your app, or you are missing your shadows - it's really a "pick your poison" issue currently.

I spent a ton of time trying to find a solution that could enable both, without success :(

@batzen
Copy link

batzen commented May 10, 2023

@Tetedeiench You can solve both issues. I solved them in ControlzEx.
Will try to have a look at the Avalonia sources during the weekend. Maybe I can apply the same tricks/hacks here.

@navhaxs
Copy link

navhaxs commented Jun 4, 2023

Hi just a friendly bump on this, maybe @batzen? :)

I just saw the 11.0 RC dropped (❤️!), so would be good to see if this can be fixed soon-ish

As a workaround I personally am doing this to fix my window drop shadows, as I am rolling my own window chrome in my app:

this.Loaded += (e, s) =>
	{
	    updateWin32Border(this.WindowState);
	};

this.GetObservable(Window.WindowStateProperty)
    .Subscribe(v =>
    {
        updateWin32Border(v);
    });
void updateWin32Border(WindowState v)
{
    if (v != WindowState.Maximized)
    {

        var margins = new Win32.MARGINS
        {
            cyBottomHeight = 1,
            cxRightWidth = 1,
            cxLeftWidth = 1,
            cyTopHeight = 1
        };

        Win32.DwmExtendFrameIntoClientArea(this.TryGetPlatformHandle().Handle, ref margins);
    }
}

@batzen
Copy link

batzen commented Jun 4, 2023

Sorry for the delay.
I tried to see what's wrong, but on my machine there is no flickering during resize and no white flash during show.
Both have been bugs in Windows itself and were, at least it looks like that, fixed in more recent Windows 11 versions.
I built mitigations for those bugs in ControlzEx before they were fixed in Windows, but those mitigations involve handling NCCALCSIZE and ERASEBKGND.
I don't think it would be wise to start handling those in Avalonia.

The only thing I noticed is that the content lags a bit behind a resize, but the background of the not yet rendered area is transparent.
So it's a bit annoying, but not worth much effort, as some lag behind is also present in Explorer and even more in Chrome etc..

@navhaxs
Copy link

navhaxs commented Jun 5, 2023

Thanks @batzen!

If that's the case, can I kindly suggest we revert #8393 ?

Seeing comments like #8393 (comment)

@James-Morrell
Copy link

I know it's been a while, but any update on this issue?

Still seems broken in V11.0.3.

@navhaxs
Copy link

navhaxs commented Feb 18, 2024

Seems to me that this been fixed on latest Avalonia 🎉. I tested 11.0.9 release.
Can someone double-check? If confirmed can close this issue :)

@timunie
Copy link
Contributor

timunie commented Feb 18, 2024

Closing it acc to feedback. If issue comes back, open a new bug report.

@timunie timunie closed this as completed Feb 18, 2024
@navhaxs
Copy link

navhaxs commented Mar 2, 2024

Apologies, this is actually still broken on Windows 10.

On Windows 11 we get the drop shadows, but not on Windows 10. Suppose most people are on Windows 11 nowadays and so don't run into this bug.

@rabbitism
Copy link
Contributor

I got same issue.

@timunie
Copy link
Contributor

timunie commented Mar 5, 2024

@rabbitism @navhaxs could you check again using latest nightly builds?

@timunie timunie reopened this Mar 5, 2024
@navhaxs
Copy link

navhaxs commented Mar 6, 2024

Just tested on 3e51397 (current master), confirming still broken on Windows 10

image

As you can see when you zoom in, there are no drop shadows. Regression quoted below -

I did some digging and found that this is a regression caused by #8393

Current behaviour on master image

If I revert the changes from the PR, then the drop shadow comes back image

i.e. change var defaultMargin = _isUsingComposition ? 0 : 1; to var defaultMargin = 1;

@timunie
Copy link
Contributor

timunie commented Mar 6, 2024

/cc @emmauss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants