5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 08:10:56 +08:00

[windows] Disable frameless decorations during fullscreen (#2288)

Otherwise this leads to thin transparent lines on the window borders on older Windows versions.
This commit is contained in:
stffabi 2023-01-11 15:22:48 +01:00 committed by GitHub
parent 05679e70d0
commit aaf039bcff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 17 deletions

View File

@ -81,14 +81,17 @@ type MONITORINFO struct {
DwFlags uint32
}
func ExtendFrameIntoClientArea(hwnd uintptr) {
func ExtendFrameIntoClientArea(hwnd uintptr, extend bool) {
// -1: Adds the default frame styling (aero shadow and e.g. rounded corners on Windows 11)
// Also shows the caption buttons if transparent ant translucent but they don't work.
// 0: Adds the default frame styling but no aero shadow, does not show the caption buttons.
// 1: Adds the default frame styling (aero shadow and e.g. rounded corners on Windows 11) but no caption buttons
// are shown if transparent ant translucent.
margins := &MARGINS{1, 1, 1, 1} // Only extend 1 pixel to have the default frame styling but no caption buttons
if err := dwmExtendFrameIntoClientArea(hwnd, margins); err != nil {
var margins MARGINS
if extend {
margins = MARGINS{1, 1, 1, 1} // Only extend 1 pixel to have the default frame styling but no caption buttons
}
if err := dwmExtendFrameIntoClientArea(hwnd, &margins); err != nil {
log.Fatal(fmt.Errorf("DwmExtendFrameIntoClientArea failed: %s", err))
}
}

View File

@ -31,6 +31,8 @@ type Window struct {
theme winoptions.Theme
themeChanged bool
framelessWithDecorations bool
OnSuspend func()
OnResume func()
dragging bool
@ -39,6 +41,8 @@ type Window struct {
}
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo, chromium *edge.Chromium) *Window {
windowsOptions := appoptions.Windows
result := &Window{
frontendOptions: appoptions,
minHeight: appoptions.MinHeight,
@ -49,13 +53,15 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
isActive: true,
themeChanged: true,
chromium: chromium,
framelessWithDecorations: appoptions.Frameless && (windowsOptions == nil || !windowsOptions.DisableFramelessWindowDecorations),
}
result.SetIsForm(true)
var exStyle int
if appoptions.Windows != nil {
if windowsOptions != nil {
exStyle = w32.WS_EX_CONTROLPARENT | w32.WS_EX_APPWINDOW
if appoptions.Windows.WindowIsTranslucent {
if windowsOptions.WindowIsTranslucent {
exStyle |= w32.WS_EX_NOREDIRECTIONBITMAP
}
}
@ -72,7 +78,7 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
result.SetParent(parent)
loadIcon := true
if appoptions.Windows != nil && appoptions.Windows.DisableWindowIcon == true {
if windowsOptions != nil && windowsOptions.DisableWindowIcon == true {
loadIcon = false
}
if loadIcon {
@ -85,8 +91,8 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
win32.SetBackgroundColour(result.Handle(), appoptions.BackgroundColour.R, appoptions.BackgroundColour.G, appoptions.BackgroundColour.B)
}
if appoptions.Windows != nil {
result.theme = appoptions.Windows.Theme
if windowsOptions != nil {
result.theme = windowsOptions.Theme
} else {
result.theme = winoptions.SystemDefault
}
@ -102,18 +108,18 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
result.UpdateTheme()
if appoptions.Windows != nil {
result.OnSuspend = appoptions.Windows.OnSuspend
result.OnResume = appoptions.Windows.OnResume
if appoptions.Windows.WindowIsTranslucent {
if windowsOptions != nil {
result.OnSuspend = windowsOptions.OnSuspend
result.OnResume = windowsOptions.OnResume
if windowsOptions.WindowIsTranslucent {
if !win32.SupportsBackdropTypes() {
result.SetTranslucentBackground()
} else {
win32.EnableTranslucency(result.Handle(), win32.BackdropType(appoptions.Windows.BackdropType))
win32.EnableTranslucency(result.Handle(), win32.BackdropType(windowsOptions.BackdropType))
}
}
if appoptions.Windows.DisableWindowIcon {
if windowsOptions.DisableWindowIcon {
result.DisableIcon()
}
}
@ -131,6 +137,12 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
}
func (w *Window) Fullscreen() {
if w.Form.IsFullScreen() {
return
}
if w.framelessWithDecorations {
win32.ExtendFrameIntoClientArea(w.Handle(), false)
}
w.Form.SetMaxSize(0, 0)
w.Form.SetMinSize(0, 0)
w.Form.Fullscreen()
@ -140,6 +152,9 @@ func (w *Window) UnFullscreen() {
if !w.Form.IsFullScreen() {
return
}
if w.framelessWithDecorations {
win32.ExtendFrameIntoClientArea(w.Handle(), true)
}
w.Form.UnFullscreen()
w.SetMinSize(w.minWidth, w.minHeight)
w.SetMaxSize(w.maxWidth, w.maxHeight)
@ -231,8 +246,8 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
// This Option is not affected by returning 0 in WM_NCCALCSIZE.
// As a result we have hidden the titlebar but still have the default window frame styling.
// See: https://docs.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea#remarks
if winoptions := w.frontendOptions.Windows; winoptions == nil || !winoptions.DisableFramelessWindowDecorations {
win32.ExtendFrameIntoClientArea(w.Handle())
if w.framelessWithDecorations {
win32.ExtendFrameIntoClientArea(w.Handle(), true)
}
case w32.WM_NCCALCSIZE:
// Disable the standard frame by allowing the client area to take the full

View File

@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `EnableFraudulentWebsiteDetection` option to opt-in to scan services for fraudulent content, such as malware or phishing attempts. Older releases had the scan services per default activated. Added by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2269)
### Changed
- Improved fullscreen mode for frameless window on Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279)
- Improved fullscreen mode for frameless window on Windows. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279) and [PR](https://github.com/wailsapp/wails/pull/2288)
- On Windows unmaximising a window has no effect anymore when the window is in fullscreen mode, this makes it consistent with e.g. macOS. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2279)
- Frameless resize now sets the cursor on documentElement, otherwise resizing cursor won't be shown outside of the body rectangle. Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2289)