-
Notifications
You must be signed in to change notification settings - Fork 16.4k
feat: support vibrancy on Windows #30298
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
Conversation
53c1270
to
cffe342
Compare
cffe342
to
7481254
Compare
7481254
to
6995bcc
Compare
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/ |
@riverar is there a better supported API surface I should instead look towards? |
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. |
@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"? |
In agreement with @riverar we should avoid using undocumented / unsupported windows APIs here |
typedef BOOL(WINAPI * pSetWindowCompositionAttribute)(HWND, | ||
WINCOMPATTRDATA*); | ||
const pSetWindowCompositionAttribute SetWindowCompositionAttribute = | ||
(pSetWindowCompositionAttribute)GetProcAddress( |
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.
use reinterpret_cast
instead of C-style cast
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.
marking request-changes to reflect conversation
Is this going to be supported using public API on Windows 11 using |
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). |
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.) |
https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
For Mica, I believe you can just directly use the Windows::UI::Composition APIs, and this window attribute isn't required. |
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. |
@riverar awesome, thanks! i'll get on that this week 🙇🏻♀️ |
This comment was marked as off-topic.
This comment was marked as off-topic.
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. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Hey! Someone has found a better Api for both acrylic and mica! |
It's not available in a stable release of Windows yet, and won't be backported to the existing ones. |
* `appearance-based` | ||
* `light` | ||
* `dark` |
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.
(nit) should annotate these three as deprecated here
* `medium-light` | ||
* `ultra-dark` |
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.
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_ |
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.
Let's put this under a separate name for Windows
@@ -1318,6 +1342,51 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() { | |||
return false; | |||
} | |||
|
|||
void NativeWindowViews::SetVibrancy(const std::string& type) { |
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.
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
std::string color_string = type.substr(1); | ||
if (!base::HexStringToBytes(color_string, &bytes)) |
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.
std::string color_string = type.substr(1); | |
if (!base::HexStringToBytes(color_string, &bytes)) | |
type.remove_prefix(1); | |
if (!base::HexStringToBytes(type, &bytes)) |
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.
@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. |
Great work! But unfortunatly these docs are old, and dont say anything about Mica, https://docs.microsoft.com/en-us/uwp/api/windows.ui.composition.compositor.createhostbackdropbrush?view=winrt-22621 |
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. |
Maybe @Levminer has read this article from Windows Lastest: Windows 11 22H2 is bringing Mica/Acrylic design to more Win32 desktop apps. |
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 |
Closed in favor of #38163 |
Description of Change
Closes #16391.
Closes #29937.
Adds vibrancy support for BrowserWindows on Windows.
Screenshot (
vibrancy: 'blur'
):Screenshot (
vibrancy: '#1F1F0BE5'
):Checklist
npm test
passesRelease Notes
Notes: Adds vibrancy support for BrowserWindows on Windows.