Rename TranslucencyType -> BackdropType. Rename BackdropType consts. Add documentation for this option.

This commit is contained in:
Lea Anthony 2022-09-20 09:49:13 +10:00
commit 2661eca2cc
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
4 changed files with 52 additions and 21 deletions

View file

@ -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")
}
}

View file

@ -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))
}
}

View file

@ -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

View file

@ -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<br/>
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.