From 95a5b926fd282e315f8f393cfbcbffbdae4fcbb1 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 18 Dec 2024 07:45:33 +1100 Subject: [PATCH] [windows] Improve minimise and restore window drawing --- docs/src/content/docs/changelog.mdx | 1 + v3/pkg/application/webview_window_windows.go | 25 +++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/docs/src/content/docs/changelog.mdx b/docs/src/content/docs/changelog.mdx index 09e1cbaaf0b..95bddba3457 100644 --- a/docs/src/content/docs/changelog.mdx +++ b/docs/src/content/docs/changelog.mdx @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved build assets to platform specific directories by [@leaanthony](https://github.com/leaanthony) - Moved and renamed Taskfiles to platform specific directories by [@leaanthony](https://github.com/leaanthony) - Created a much better experience when `index.html` is missing by [@leaanthony](https://github.com/leaanthony) +- [Windows] Improved performance of minimise and restore by [@leaanthony](https://github.com/leaanthony). Based on original [PR](https://github.com/wailsapp/wails/pull/3955) by [562589540](https://github.com/562589540) ## v3.0.0-alpha.8.3 - 2024-12-07 diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 85c32505c24..eeba9c27c2e 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -70,6 +70,9 @@ type windowsWebviewWindow struct { // Window move debouncer moveDebouncer func(func()) + // isMinimizing indicates whether the window is currently being minimized + // Used to prevent unnecessary redraws during minimize/restore operations + isMinimizing bool } func (w *windowsWebviewWindow) cut() { @@ -1059,8 +1062,10 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp case w32.SIZE_MAXIMIZED: w.parent.emit(events.Windows.WindowMaximise) case w32.SIZE_RESTORED: + w.isMinimizing = false w.parent.emit(events.Windows.WindowRestore) case w32.SIZE_MINIMIZED: + w.isMinimizing = true w.parent.emit(events.Windows.WindowMinimise) } @@ -1188,7 +1193,7 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp // In Full-Screen mode we don't need to adjust anything // It essential we have the flag here, that is set before SetWindowPos in fullscreen/unfullscreen // because the native size might not yet reflect we are in fullscreen during this event! - w.chromium.SetPadding(edge.Rect{}) + w.setPadding(edge.Rect{}) } else if w.isMaximised() { // If the window is maximized we must adjust the client area to the work area of the monitor. Otherwise // some content goes beyond the visible part of the monitor. @@ -1227,16 +1232,16 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp Right: int32(rect.X + rect.Width), Bottom: int32(rect.Y + rect.Height), } - w.chromium.SetPadding(edge.Rect{}) + w.setPadding(edge.Rect{}) } else { // This is needed to workaround the resize flickering in frameless mode with WindowDecorations // See: https://stackoverflow.com/a/6558508 - // The workaround originally suggests to decrese the bottom 1px, but that seems to bring up a thin - // white line on some Windows-Versions, due to DrawBackground using also this reduces ClientSize. + // The workaround from the SO answer suggests to reduce the bottom of the window by 1px. + // However this would result in loosing 1px of the WebView content. // Increasing the bottom also worksaround the flickering but we would loose 1px of the WebView content // therefore let's pad the content with 1px at the bottom. rgrc.Bottom += 1 - w.chromium.SetPadding(edge.Rect{Bottom: 1}) + w.setPadding(edge.Rect{Bottom: 1}) } return 0 } @@ -1746,7 +1751,7 @@ func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message strin count, err := objs.GetCount() if err != nil { - globalApplication.error(err.Error()) + globalApplication.error("cannot get count: %s", err.Error()) return } @@ -1846,3 +1851,11 @@ func (w *windowsWebviewWindow) setIgnoreMouseEvents(ignore bool) { } w32.SetWindowLong(w.hwnd, w32.GWL_EXSTYLE, uint32(exStyle)) } + +func (w *windowsWebviewWindow) setPadding(padding edge.Rect) { + // Skip SetPadding if window is being minimized to prevent flickering + if w.isMinimizing { + return + } + w.chromium.SetPadding(padding) +}