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

feat: support Mica/Acrylic on Windows #38163

Merged
merged 2 commits into from May 15, 2023
Merged

feat: support Mica/Acrylic on Windows #38163

merged 2 commits into from May 15, 2023

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented May 3, 2023

Description of Change

Supersedes #30298.

Closes #16391.
Closes #29937.

Adds support for background material effects on Windows with win.setBackgroundMaterial(material).

Checklist

Release Notes

Notes: Add support for Mica and Acrylic background effects on Windows.

@codebytere codebytere added semver/minor backwards-compatible functionality target/24-x-y PR should also be added to the "24-x-y" branch. target/25-x-y PR should also be added to the "25-x-y" branch. labels May 3, 2023
@codebytere codebytere requested review from deepak1556, mlaurencin and a team May 3, 2023 10:49
@electron-cation electron-cation bot added new-pr 🌱 PR opened in the last 24 hours api-review/requested 🗳 labels May 3, 2023
@felixrieseberg
Copy link
Member

I can't believe you did this in like 30 LoC, this is so much simpler than I thought it would have been.

Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this feature work together with our custom titlebar implementation where we basically extend into the non-client area ?

#if BUILDFLAG(IS_WIN)
// DWMWA_USE_HOSTBACKDROPBRUSH is only supported on Windows 11 22H2 and up.
if (base::win::GetVersion() < base::win::Version::WIN11_22H2)
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this surface an error to the user rather than silent termination ?

Copy link
Member Author

@codebytere codebytere May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't for comparable version-gated features like this - historically it's just been clearly noted in docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think silently failing is fine here

DwmSetWindowAttribute(GetAcceleratedWidget(), DWMWA_SYSTEMBACKDROP_TYPE,
&backdrop_type, sizeof(backdrop_type));
if (FAILED(result))
LOG(WARNING) << "Failed to set background material to " << material;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User facing error instead of LOG ?

Copy link
Member Author

@codebytere codebytere May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also open to that, but we don't have a clear convention there either really 🤔 for dark mode for example we don't surface a user facing error:

TrySetWindowTheme(hWnd, dark);

Beyond that - we don't really get a good error message from the call sadly, so all we'd really be able to say is "it failed"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we set this in the constructor we can't safely have a user facing error afaik anyway. I think the LOG is fine here. We shouldn't fail to construct a window just because the DWM call got lost

shell/browser/api/electron_api_base_window.cc Outdated Show resolved Hide resolved
@codebytere codebytere requested a review from deepak1556 May 8, 2023 07:47
Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

shell/browser/api/electron_api_base_window.h Outdated Show resolved Hide resolved
docs/api/browser-window.md Show resolved Hide resolved
Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@jkleinsc jkleinsc merged commit e19500f into main May 15, 2023
17 checks passed
@jkleinsc jkleinsc deleted the windows-backdrop branch May 15, 2023 20:31
@release-clerk
Copy link

release-clerk bot commented May 15, 2023

Release Notes Persisted

Add support for Mica and Acrylic background effects on Windows.

@trop
Copy link
Contributor

trop bot commented May 15, 2023

I was unable to backport this PR to "24-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/24-x-y PR should also be added to the "24-x-y" branch. label May 15, 2023
@trop
Copy link
Contributor

trop bot commented May 15, 2023

I was unable to backport this PR to "25-x-y" cleanly;
you will need to perform this backport manually.

@electron electron deleted a comment from trop bot May 17, 2023
@trop
Copy link
Contributor

trop bot commented May 17, 2023

@codebytere has manually backported this PR to "25-x-y", please check out #38357

@trop
Copy link
Contributor

trop bot commented May 17, 2023

@codebytere has manually backported this PR to "24-x-y", please check out #38361

@michalzaq12
Copy link
Contributor

michalzaq12 commented May 28, 2023

@codebytere Is this the intended behavior? The effect only applies to the title bar?
image

@SudoVanilla
Copy link

Interesting, with Glasstron this was a bug, not sure if that is suppose to happen.

@kochie
Copy link

kochie commented May 28, 2023

For vibrancy on macos you need to have no background color in the div. Maybe double check that your div is transparent? Nope, I get the above as well.

@ghost
Copy link

ghost commented May 30, 2023

So sorry for all you that are suscribed but this is SO cool! I'm surprised how little lines it takes to do something like this

@blueset
Copy link

blueset commented Jun 6, 2023

@codebytere Is this the intended behavior? The effect only applies to the title bar? image

Having the same issue. Is this expected? Is it possible to apply also Mica to the web content background?

@ghost
Copy link

ghost commented Jun 6, 2023

Have you tried with background: none;, background-color: none;, background: transparent;, background-color: transparent; (to <body>)?

@blueset
Copy link

blueset commented Jun 6, 2023

@aitor-gomila:
Have you tried with background: none;, background-color: none;, background: transparent;, background-color: transparent; (to <body>)?

image

Yes, I’ve tried all 4 combinations on both <body> and <html>, and it still produces the same result.

Here’s my Electron Fiddle code to repro this: https://gist.github.com/blueset/b406e2d1bd9218a16b599e72a3ee82c7

@oliverschwendener
Copy link

@blueset @michalzaq12 I had the same issue, but it worked when I added transparent: true to the BrowserWindow constructor options. Using electron 25.1.0

@blueset
Copy link

blueset commented Jun 9, 2023

@oliverschwendener
I had the same issue, but it worked when I added transparent: true to the BrowserWindow constructor options. Using electron 25.1.0

Setting transparent: true partially solves the problem, but the window would become unresizable. See #38454.

@gaetandezeiraud
Copy link

I confirm, same problem.

@JerryI
Copy link

JerryI commented Oct 24, 2023

I confirm, same problem.

just bump into the same issue.
Confirmed on Win11

@tiagorangel2011
Copy link

bump, also happening to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/approved ✅ merged/24-x-y PR was merged to the "24-x-y" branch merged/25-x-y PR was merged to the "25-x-y" branch. semver/minor backwards-compatible functionality
Projects
None yet