From 1c34c252ccb391539174f4356835e66aef00eed6 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 1 Dec 2024 09:52:06 +1100 Subject: [PATCH] Remove resize debounce setting for windows. Optimise resizing performance on windows automatically. --- v3/pkg/application/application_windows.go | 4 --- v3/pkg/application/webview_window_options.go | 5 --- v3/pkg/application/webview_window_windows.go | 37 +++++++++++--------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/v3/pkg/application/application_windows.go b/v3/pkg/application/application_windows.go index ee2d411aa..78d75f17a 100644 --- a/v3/pkg/application/application_windows.go +++ b/v3/pkg/application/application_windows.go @@ -137,17 +137,13 @@ func (m *windowsApp) run() error { // Check if there is 1 parameter passed to the application // and if the extension matches the options.FileAssociations string - println("Checking args") if len(os.Args) == 2 { arg := os.Args[1] ext := filepath.Ext(arg) - println("Got extension: ", ext) if slices.Contains(m.parent.options.FileAssociations, ext) { - println("Slices contains") eventContext := newApplicationEventContext() eventContext.setOpenedWithFile(arg) // EmitEvent application started event - println("sending event") applicationEvents <- &ApplicationEvent{ Id: uint(events.Common.ApplicationOpenedWithFile), ctx: eventContext, diff --git a/v3/pkg/application/webview_window_options.go b/v3/pkg/application/webview_window_options.go index 0abe58ab5..884b36870 100644 --- a/v3/pkg/application/webview_window_options.go +++ b/v3/pkg/application/webview_window_options.go @@ -256,11 +256,6 @@ type WindowsWindow struct { // Default: false WebviewGpuIsDisabled bool - // ResizeDebounceMS is the amount of time to debounce redraws of webview2 - // when resizing the window - // Default: 0 - ResizeDebounceMS uint16 - // Disable the menu bar for this window // Default: false DisableMenu bool diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index 04d3597fd..b253b9532 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "syscall" "time" "unsafe" @@ -57,9 +58,8 @@ type windowsWebviewWindow struct { previousWindowPlacement w32.WINDOWPLACEMENT // Webview - chromium *edge.Chromium - hasStarted bool - resizeDebouncer func(func()) + chromium *edge.Chromium + hasStarted bool // resizeBorder* is the width/height of the resize border in pixels. resizeBorderWidth int32 @@ -366,10 +366,6 @@ func (w *windowsWebviewWindow) run() { w.setWindowMask(options.Windows.WindowMask) } - if options.Windows.ResizeDebounceMS > 0 { - w.resizeDebouncer = debounce.New(time.Duration(options.Windows.ResizeDebounceMS) * time.Millisecond) - } - if options.InitialPosition == WindowCentered { w.center() } else { @@ -1006,6 +1002,8 @@ func (w *windowsWebviewWindow) isActive() bool { return w32.GetForegroundWindow() == w.hwnd } +var resizePending int32 + func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintptr { switch msg { case w32.WM_ACTIVATE: @@ -1064,20 +1062,24 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp case w32.SIZE_MINIMIZED: w.parent.emit(events.Windows.WindowMinimise) } + if w.parent.options.Frameless && wparam == w32.SIZE_MINIMIZED { // If the window is frameless, and we are minimizing, then we need to suppress the Resize on the // WebView2. If we don't do this, restoring does not work as expected and first restores with some wrong // size during the restore animation and only fully renders when the animation is done. This highly // depends on the content in the WebView, see https://github.com/wailsapp/wails/issues/1319 - } else if w.resizeDebouncer != nil { - w.resizeDebouncer(func() { - InvokeSync(func() { - w.chromium.Resize() - }) - w.parent.emit(events.Windows.WindowDidResize) - }) } else { - w.chromium.Resize() + if atomic.CompareAndSwapInt32(&resizePending, 0, 1) { + go func() { + // Wait for next vsync-like interval + time.Sleep(time.Millisecond) // ~60fps timing + InvokeSync(func() { + w.chromium.Resize() + atomic.StoreInt32(&resizePending, 0) + w.parent.emit(events.Windows.WindowDidResize) + }) + }() + } } return 0 @@ -1491,7 +1493,7 @@ func (w *windowsWebviewWindow) setupChromium() { //println(windowName) //if windowName == "Chrome_RenderWidgetHostHWND" { err := w32.RegisterDragDrop(hwnd, w.dropTarget) - if err != nil && err != syscall.Errno(w32.DRAGDROP_E_ALREADYREGISTERED) { + if err != nil && !errors.Is(err, syscall.Errno(w32.DRAGDROP_E_ALREADYREGISTERED)) { globalApplication.error("Error registering drag and drop: " + err.Error()) } //} @@ -1547,6 +1549,9 @@ func (w *windowsWebviewWindow) setupChromium() { if err != nil { globalApplication.fatal(err.Error()) } + if settings == nil { + globalApplication.fatal("Error getting settings") + } err = settings.PutAreDefaultContextMenusEnabled(debugMode || !w.parent.options.DefaultContextMenuDisabled) if err != nil { globalApplication.fatal(err.Error())