feat: support Mica/Acrylic on Windows (#38163)
* feat: support Mica/Acrylic on Windows * chore: feedback from review
This commit is contained in:
parent
c2d7164021
commit
e19500fa03
10 changed files with 68 additions and 0 deletions
|
@ -864,6 +864,10 @@ void BaseWindow::SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
|||
window_->SetVibrancy(type);
|
||||
}
|
||||
|
||||
void BaseWindow::SetBackgroundMaterial(const std::string& material_type) {
|
||||
window_->SetBackgroundMaterial(material_type);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
std::string BaseWindow::GetAlwaysOnTopLevel() {
|
||||
return window_->GetAlwaysOnTopLevel();
|
||||
|
@ -1267,6 +1271,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
|
||||
#endif
|
||||
.SetMethod("setVibrancy", &BaseWindow::SetVibrancy)
|
||||
.SetMethod("setBackgroundMaterial", &BaseWindow::SetBackgroundMaterial)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
.SetMethod("isHiddenInMissionControl",
|
||||
|
|
|
@ -190,6 +190,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
|||
bool IsVisibleOnAllWorkspaces();
|
||||
void SetAutoHideCursor(bool auto_hide);
|
||||
virtual void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value);
|
||||
void SetBackgroundMaterial(const std::string& vibrancy);
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
std::string GetAlwaysOnTopLevel();
|
||||
|
|
|
@ -249,6 +249,11 @@ void NativeWindow::InitFromOptions(const gin_helper::Dictionary& options) {
|
|||
if (options.Get(options::kVibrancyType, &type)) {
|
||||
SetVibrancy(type);
|
||||
}
|
||||
#elif BUILDFLAG(IS_WIN)
|
||||
std::string material;
|
||||
if (options.Get(options::kBackgroundMaterial, &material)) {
|
||||
SetBackgroundMaterial(material);
|
||||
}
|
||||
#endif
|
||||
std::string color;
|
||||
if (options.Get(options::kBackgroundColor, &color)) {
|
||||
|
@ -445,6 +450,8 @@ bool NativeWindow::AddTabbedWindow(NativeWindow* window) {
|
|||
|
||||
void NativeWindow::SetVibrancy(const std::string& type) {}
|
||||
|
||||
void NativeWindow::SetBackgroundMaterial(const std::string& type) {}
|
||||
|
||||
void NativeWindow::SetTouchBar(
|
||||
std::vector<gin_helper::PersistentDictionary> items) {}
|
||||
|
||||
|
|
|
@ -216,6 +216,8 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// Vibrancy API
|
||||
virtual void SetVibrancy(const std::string& type);
|
||||
|
||||
virtual void SetBackgroundMaterial(const std::string& type);
|
||||
|
||||
// Traffic Light API
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
virtual void SetWindowButtonVisibility(bool visible) = 0;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "shell/browser/native_window_views.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include <dwmapi.h>
|
||||
#include <wrl/client.h>
|
||||
#endif
|
||||
|
||||
|
@ -69,6 +70,7 @@
|
|||
|
||||
#elif BUILDFLAG(IS_WIN)
|
||||
#include "base/win/win_util.h"
|
||||
#include "base/win/windows_version.h"
|
||||
#include "content/public/common/color_parser.h"
|
||||
#include "shell/browser/ui/views/win_frame_view.h"
|
||||
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
|
||||
|
@ -83,6 +85,19 @@ namespace electron {
|
|||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
|
||||
DWM_SYSTEMBACKDROP_TYPE GetBackdropFromString(const std::string& material) {
|
||||
if (material == "none") {
|
||||
return DWMSBT_NONE;
|
||||
} else if (material == "acrylic") {
|
||||
return DWMSBT_TRANSIENTWINDOW;
|
||||
} else if (material == "mica") {
|
||||
return DWMSBT_MAINWINDOW;
|
||||
} else if (material == "tabbed") {
|
||||
return DWMSBT_TABBEDWINDOW;
|
||||
}
|
||||
return DWMSBT_AUTO;
|
||||
}
|
||||
|
||||
// Similar to the ones in display::win::ScreenWin, but with rounded values
|
||||
// These help to avoid problems that arise from unresizable windows where the
|
||||
// original ceil()-ed values can cause calculation errors, since converting
|
||||
|
@ -1379,6 +1394,21 @@ bool NativeWindowViews::IsMenuBarVisible() {
|
|||
return root_view_->IsMenuBarVisible();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetBackgroundMaterial(const std::string& material) {
|
||||
#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;
|
||||
|
||||
DWM_SYSTEMBACKDROP_TYPE backdrop_type = GetBackdropFromString(material);
|
||||
HRESULT result =
|
||||
DwmSetWindowAttribute(GetAcceleratedWidget(), DWMWA_SYSTEMBACKDROP_TYPE,
|
||||
&backdrop_type, sizeof(backdrop_type));
|
||||
if (FAILED(result))
|
||||
LOG(WARNING) << "Failed to set background material to " << material;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetVisibleOnAllWorkspaces(
|
||||
bool visible,
|
||||
bool visibleOnFullScreen,
|
||||
|
|
|
@ -138,6 +138,7 @@ class NativeWindowViews : public NativeWindow,
|
|||
bool IsMenuBarAutoHide() override;
|
||||
void SetMenuBarVisibility(bool visible) override;
|
||||
bool IsMenuBarVisible() override;
|
||||
void SetBackgroundMaterial(const std::string& type) override;
|
||||
|
||||
void SetVisibleOnAllWorkspaces(bool visible,
|
||||
bool visibleOnFullScreen,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue