From 2661eca2cc25b887ac0b04c19be5a4b582ab10de Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 20 Sep 2022 09:49:13 +1000 Subject: [PATCH] Rename TranslucencyType -> BackdropType. Rename BackdropType consts. Add documentation for this option. --- .../frontend/desktop/windows/win32/theme.go | 23 ++++++++------ .../frontend/desktop/windows/window.go | 5 ++- v2/pkg/options/windows/windows.go | 14 ++++----- website/docs/reference/options.mdx | 31 ++++++++++++++++++- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/v2/internal/frontend/desktop/windows/win32/theme.go b/v2/internal/frontend/desktop/windows/win32/theme.go index 89aa9fc74..2effae5ad 100644 --- a/v2/internal/frontend/desktop/windows/win32/theme.go +++ b/v2/internal/frontend/desktop/windows/win32/theme.go @@ -17,14 +17,9 @@ const DwmwaSystemBackdropType DWMWINDOWATTRIBUTE = 38 const SPI_GETHIGHCONTRAST = 0x0042 const HCF_HIGHCONTRASTON = 0x00000001 +// BackdropType defines the type of translucency we wish to use type BackdropType int32 -const DwmsbtAuto BackdropType = 0 -const DwmsbtDisable = 1 // None -const DwmsbtMainWindow = 2 // Mica -const DwmsbtTransientWindow = 3 // Acrylic -const DwmsbtTabbedWindow = 4 // Tabbed - func dwmSetWindowAttribute(hwnd uintptr, dwAttribute DWMWINDOWATTRIBUTE, pvAttribute unsafe.Pointer, cbAttribute uintptr) { ret, _, err := procDwmSetWindowAttribute.Call( hwnd, @@ -46,10 +41,18 @@ func SupportsCustomThemes() bool { return IsWindowsVersionAtLeast(10, 0, 17763) } +func SupportsBackdropTypes() bool { + return IsWindowsVersionAtLeast(10, 0, 22621) +} + +func SupportsImmersiveDarkMode() bool { + return IsWindowsVersionAtLeast(10, 0, 18985) +} + func SetTheme(hwnd uintptr, useDarkMode bool) { - if IsWindowsVersionAtLeast(10, 0, 17763) { + if SupportsThemes() { attr := DwmwaUseImmersiveDarkModeBefore20h1 - if IsWindowsVersionAtLeast(10, 0, 18985) { + if SupportsImmersiveDarkMode() { attr = DwmwaUseImmersiveDarkMode } var winDark int32 @@ -61,10 +64,10 @@ func SetTheme(hwnd uintptr, useDarkMode bool) { } func EnableTranslucency(hwnd uintptr, backdrop BackdropType) { - if IsWindowsVersionAtLeast(10, 0, 22579) { + if SupportsBackdropTypes() { dwmSetWindowAttribute(hwnd, DwmwaSystemBackdropType, unsafe.Pointer(&backdrop), unsafe.Sizeof(backdrop)) } else { - println("Warning: Translucency unavailable on Windows < 22579") + println("Warning: Translucency type unavailable on Windows < 22621") } } diff --git a/v2/internal/frontend/desktop/windows/window.go b/v2/internal/frontend/desktop/windows/window.go index 0d12df60c..1b511d34f 100644 --- a/v2/internal/frontend/desktop/windows/window.go +++ b/v2/internal/frontend/desktop/windows/window.go @@ -105,11 +105,10 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope result.OnSuspend = appoptions.Windows.OnSuspend result.OnResume = appoptions.Windows.OnResume if appoptions.Windows.WindowIsTranslucent { - // TODO: Migrate to win32 package - if !win32.IsWindowsVersionAtLeast(10, 0, 22579) { + if !win32.SupportsBackdropTypes() { result.SetTranslucentBackground() } else { - win32.EnableTranslucency(result.Handle(), win32.BackdropType(appoptions.Windows.TranslucencyType)) + win32.EnableTranslucency(result.Handle(), win32.BackdropType(appoptions.Windows.BackdropType)) } } diff --git a/v2/pkg/options/windows/windows.go b/v2/pkg/options/windows/windows.go index 5c18d1737..95c446fd9 100644 --- a/v2/pkg/options/windows/windows.go +++ b/v2/pkg/options/windows/windows.go @@ -27,11 +27,11 @@ const ( type BackdropType int32 const ( - Auto BackdropType = 0 - Disable BackdropType = 1 // None - MainWindow BackdropType = 2 // Mica - TransientWindow BackdropType = 3 // Acrylic - TabbedWindow BackdropType = 4 // Tabbed + Auto BackdropType = 0 + None BackdropType = 1 + Mica BackdropType = 2 + Acrylic BackdropType = 3 + Tabbed BackdropType = 4 ) func RGB(r, g, b uint8) int32 { @@ -81,8 +81,8 @@ type Options struct { // Custom settings for dark/light mode CustomTheme *ThemeSettings - // Windows 11 22579 minimum - TranslucencyType BackdropType + // Select the type of translucent backdrop. Requires Windows 11 22621 or later. + BackdropType BackdropType // User messages that can be customised Messages *Messages diff --git a/website/docs/reference/options.mdx b/website/docs/reference/options.mdx index 0470aaf8d..d2d018c28 100644 --- a/website/docs/reference/options.mdx +++ b/website/docs/reference/options.mdx @@ -48,6 +48,7 @@ func main() { Windows: &windows.Options{ WebviewIsTransparent: false, WindowIsTranslucent: false, + BackdropType: windows.Mica, DisableWindowIcon: false, DisableFramelessWindowDecorations: false, WebviewUserDataPath: "", @@ -381,11 +382,39 @@ Type: `bool` #### WindowIsTranslucent Setting this to `true` will make the window background translucent. Often combined -with [WebviewIsTransparent](#WebviewIsTransparent) to make frosty-looking applications. +with [WebviewIsTransparent](#WebviewIsTransparent). + +For Windows 11 versions before build 22621, this will use the [BlurBehind](https://learn.microsoft.com/en-us/windows/win32/dwm/blur-ovw) +method for translucency, which can be slow. For Windows 11 versions after build 22621, this will enable the +newer translucency types that are much faster. By default, the type of translucency used will be determined +by Windows. To configure this, use the [BackdropType](#BackdropType) option. Name: WindowIsTranslucent
Type: `bool` +#### BackdropType + +:::note + +Requires Windows 11 build 22621 or later. + +::: + +Sets the translucency type of the window. This is only applicable if [WindowIsTranslucent](#WindowIsTranslucent) is set to `true`. + +Name: BackdropType +Type `windows.BackdropType` + +The Type can be one of the following: + +| Value | Description | +|---------|-------------------------------------------------------------------------------------------| +| Auto | Let Windows decide which backdrop to use | +| None | Do not use translucency | +| Acrylic | Use [Acrylic](https://learn.microsoft.com/en-us/windows/apps/design/style/acrylic) effect | +| Mica | Use [Mica](https://learn.microsoft.com/en-us/windows/apps/design/style/mica) effect | +| Tabbed | Use Tabbed. This is a backdrop that is similar to Mica. | + #### DisableWindowIcon Setting this to `true` will remove the icon in the top left corner of the title bar.