Skip to content

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Jul 27, 2021

Description of Change

Closes #16391.
Closes #29937.

Adds vibrancy support for BrowserWindows on Windows.

Screenshot (vibrancy: 'blur'):

Screen Shot 2021-07-28 at 1 11 12 AM

Screenshot (vibrancy: '#1F1F0BE5'):

Screen Shot 2021-07-28 at 9 45 09 AM

Checklist

Release Notes

Notes: Adds vibrancy support for BrowserWindows on Windows.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jul 27, 2021
@codebytere codebytere force-pushed the vibrancy-support-windows branch from 53c1270 to cffe342 Compare July 28, 2021 06:44
@codebytere codebytere added the semver/minor backwards-compatible functionality label Jul 28, 2021
@codebytere codebytere force-pushed the vibrancy-support-windows branch from cffe342 to 7481254 Compare July 28, 2021 07:29
@codebytere codebytere force-pushed the vibrancy-support-windows branch from 7481254 to 6995bcc Compare July 28, 2021 07:58
@codebytere codebytere requested a review from deepak1556 July 28, 2021 07:58
@codebytere codebytere marked this pull request as ready for review July 28, 2021 07:59
@riverar
Copy link

riverar commented Jul 28, 2021

I wrote those Acrylic hacks originally [1][2]; they are not supported by Microsoft and introduce a number of problems [3]. DO NOT merge this. This is a very bad idea.

[1] https://withinrafael.com/2015/07/08/adding-the-aero-glass-blur-to-your-windows-10-apps/
[2] https://withinrafael.com/2018/02/02/adding-acrylic-blur-to-your-windows-10-apps-redstone-4-desktop-apps/
[3] File-New-Project/EarTrumpet#349

@codebytere
Copy link
Member Author

@riverar is there a better supported API surface I should instead look towards?

@riverar
Copy link

riverar commented Jul 28, 2021

There is no documented (or undocumented) path to get Acrylic into a desktop app without introducing problems, sadly. (The undocumented path used in this PR is (finally) fixed in Windows 11 builds but that's not helpful downstream and Microsoft refuses to service this in Windows 10. Incredibly annoying, I know.)

I think your best option is to adopt Mica (when those APIs come out) and we all just keep pressuring Microsoft for an official Acrylic path.

@marcelwgn
Copy link

@codebytere How does this PR address #29937? Mica and Acrylic are different things and work differently so adding acrylic does not cover Mica. Or does this close the feature request as in "there is an alternative"?

@MarshallOfSound
Copy link
Member

In agreement with @riverar we should avoid using undocumented / unsupported windows APIs here

typedef BOOL(WINAPI * pSetWindowCompositionAttribute)(HWND,
WINCOMPATTRDATA*);
const pSetWindowCompositionAttribute SetWindowCompositionAttribute =
(pSetWindowCompositionAttribute)GetProcAddress(
Copy link
Contributor

@miniak miniak Jul 29, 2021

Choose a reason for hiding this comment

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

use reinterpret_cast instead of C-style cast

Copy link
Contributor

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

marking request-changes to reflect conversation

@zcbenz zcbenz added the wip ⚒ label Aug 2, 2021
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Aug 3, 2021
@miniak
Copy link
Contributor

miniak commented Aug 10, 2021

Is this going to be supported using public API on Windows 11 using DWMWA_USE_HOSTBACKDROPBRUSH?

@sylveon
Copy link

sylveon commented Oct 2, 2021

In Windows 11, there are documented paths for both Mica and Acrylic in Win32. I heavily suggest using those and not supporting Windows 10 for vibrancy, as SetWindowCompositionAttribute is full of pitfalls, bugs, and weird issues.

Also "vibrancy" is a macOS term, Windows doesn't use it to describe its transparency effects. Suggest using another name, maybe something like backgroundBrush, or hostBackdropBrush (also that would allow devs to so something like pass both vibrancy and backgroundBrush in the window create options, and the right one for the current OS is picked).

@riverar
Copy link

riverar commented Oct 2, 2021

In Windows 11, there are documented paths for both Mica and Acrylic in Win32.

I'm not aware of any official guidance/documentation for these paths. Got a link? (Availability in the preview SDKs is not documentation and Islands is of no use here.)

@sylveon
Copy link

sylveon commented Oct 2, 2021

https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute

DWMWA_USE_HOSTBACKDROPBRUSH

Use with DwmSetWindowAttribute. Enables a non-UWP window to use host backdrop brushes. If this flag is set, then a Win32 app that calls Windows::UI::Composition APIs can build transparency effects using the host backdrop brush (see Compositor.CreateHostBackdropBrush). The retrieved value is of type BOOL. TRUE to enable host backdrop brushes for the window; otherwise, FALSE.

For Mica, I believe you can just directly use the Windows::UI::Composition APIs, and this window attribute isn't required.

@riverar
Copy link

riverar commented Oct 2, 2021

I had a chat with @sylveon offline as well and while this is a preview API in a preview SDK, we agree this will be the way forward (for Windows 11 only). 👍

So @codebytere could perhaps swap out their method for this one, add Win11 guard rails, and complete this PR.

@codebytere
Copy link
Member Author

@riverar awesome, thanks! i'll get on that this week 🙇🏻‍♀️

@electron electron deleted a comment from alfodei22 Oct 3, 2021
@ghost

This comment was marked as off-topic.

@zcbenz
Copy link
Contributor

zcbenz commented Dec 8, 2021

Why isnt anyone reviewing the pr

According to the discussion above, the best way to implement the feature is to use a new API in Windows 11, instead of the unreliable private API used in current approach.

@ghost

This comment was marked as off-topic.

@ghost
Copy link

ghost commented Dec 28, 2021

Hey! Someone has found a better Api for both acrylic and mica!
New DWMWA_SYSTEMBACKDROP_TYPE in 22523 SDK, public Win32 API for Mica. Also for Acrylic.
@codebytere
Seems like this API is working correctly and is recommended for use

@sylveon
Copy link

sylveon commented Dec 28, 2021

It's not available in a stable release of Windows yet, and won't be backported to the existing ones.

Comment on lines +1755 to +1757
* `appearance-based`
* `light`
* `dark`
Copy link
Member

Choose a reason for hiding this comment

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

(nit) should annotate these three as deprecated here

Comment on lines +1763 to +1764
* `medium-light`
* `ultra-dark`
Copy link
Member

Choose a reason for hiding this comment

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

should annotate these two as deprecated here

@@ -1742,18 +1742,48 @@ there is only one tab in the current window.

Adds a window as a tab on this window, after the tab for the window instance.

#### `win.setVibrancy(type)` _macOS_
#### `win.setVibrancy(type)` _macOS_ _Windows_
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's put this under a separate name for Windows

@codebytere codebytere self-assigned this Mar 3, 2022
@@ -1318,6 +1342,51 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
return false;
}

void NativeWindowViews::SetVibrancy(const std::string& type) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
void NativeWindowViews::SetVibrancy(const std::string& type) {
void NativeWindowViews::SetVibrancy(base::StringPiece type) {

The API code we call below allows a StringPiece, so we should use that more flexible type here too

Comment on lines +1362 to +1363
std::string color_string = type.substr(1);
if (!base::HexStringToBytes(color_string, &bytes))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::string color_string = type.substr(1);
if (!base::HexStringToBytes(color_string, &bytes))
type.remove_prefix(1);
if (!base::HexStringToBytes(type, &bytes))

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

@XFaonAE had a comment here that points to a newer API that might be officially supported upstream? If so, that sounds worth looking into?

Marking as request-changes

@ghost
Copy link

ghost commented May 18, 2022

@XFaonAE had a comment here that points to a newer API that might be officially supported upstream? If so, that sounds worth looking into?

Marking as request-changes

Just to be safe, I did test it out again on the latest dev build, and it still seem to be functioning as expected.
One thing to note is that mica was not meant to be used with system native titlebars, which is why some weird behaviour may occure, instead I recommend setting the window style to WS_CAPTION and then moving the client area as needed to hide the titlebar, then design your own titlebar. Its quite the hassle which is why i stopped usin g NodeJS entirly xD Instead I do java now

@Levminer
Copy link

Levminer commented Jun 2, 2022

Offical docs: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type?WT.mc_id=WD-MVP-5002756

@ghost
Copy link

ghost commented Jun 2, 2022

Offical docs: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type?WT.mc_id=WD-MVP-5002756

Great work! But unfortunatly these docs are old, and dont say anything about Mica,
These documentation references MAY or MAY NOT be helpfull, but they are relavant to Mica and backdrop brushes. UWP components can infact be used with Win32 which is well... that electron is based on

https://docs.microsoft.com/en-us/uwp/api/windows.ui.composition.compositor.createhostbackdropbrush?view=winrt-22621
https://github.com/microsoft/Windows.UI.Composition-Win32-Samples

@sylveon
Copy link

sylveon commented Jun 2, 2022

What do you mean old? These where published just a few days ago.

They don't refer to Mica by name but it's what you get when using DWMSBT_MAINWINDOW. You get acrylic with DWMSBT_TRANSIENTWINDOW.

@Diegorro98
Copy link

Maybe @Levminer has read this article from Windows Lastest: Windows 11 22H2 is bringing Mica/Acrylic design to more Win32 desktop apps.
On this article the mentioned docs are refereed, and the article affirms that mica/acrylic would be selectable on Win32 apps.

@Levminer
Copy link

Levminer commented Jun 2, 2022

Offical docs: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type?WT.mc_id=WD-MVP-5002756

Great work! But unfortunatly these docs are old, and dont say anything about Mica, These documentation references MAY or MAY NOT be helpfull, but they are relavant to Mica and backdrop brushes. UWP components can infact be used with Win32 which is well... that electron is based on

https://docs.microsoft.com/en-us/uwp/api/windows.ui.composition.compositor.createhostbackdropbrush?view=winrt-22621 https://github.com/microsoft/Windows.UI.Composition-Win32-Samples

As @sylveon mentiond this was posted on 05/24/2022. This is coming in build 22621 (which is the 22H2 update) coming in september or october. So this is confirmed.

EDIT: source (https://twitter.com/WithinRafael/status/1532127929810886656)

@Niclas1337
Copy link

Offical docs: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwm_systembackdrop_type?WT.mc_id=WD-MVP-5002756

Great work! But unfortunatly these docs are old, and dont say anything about Mica, These documentation references MAY or MAY NOT be helpfull, but they are relavant to Mica and backdrop brushes. UWP components can infact be used with Win32 which is well... that electron is based on
https://docs.microsoft.com/en-us/uwp/api/windows.ui.composition.compositor.createhostbackdropbrush?view=winrt-22621 https://github.com/microsoft/Windows.UI.Composition-Win32-Samples

As @sylveon mentiond this was posted on 05/24/2022. This is coming in build 22621 (which is the 22H2 update) coming in september or october. So this is confirmed.

EDIT: source (https://twitter.com/WithinRafael/status/1532127929810886656)

any updates on this? 22H2 has been released :D

@codebytere codebytere removed their assignment Apr 27, 2023
@codebytere
Copy link
Member Author

Closed in favor of #38163

@codebytere codebytere closed this May 3, 2023
@zcbenz zcbenz deleted the vibrancy-support-windows branch October 26, 2023 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Use new 'Mica' material for BrowserWindow vibrancy in Windows 11 Vibrancy Support for Windows