From 2f3eb70a4dff9cb8c7eff11be20255496e9add09 Mon Sep 17 00:00:00 2001 From: stffabi Date: Wed, 6 Dec 2023 21:59:50 +0100 Subject: [PATCH] [windows] Use msWebView2BrowserHitTransparent for non working NC area clicks on unfocused window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this patch there's a really strange behaviour if there are multiple windows. Having two windows with a webview open with an input field. Focusing the input field on one window, then focusing the input field on the second one. Then clicking directly on the non client area of the first one, e.g. to trigger a minimze, the minimize is not executed until the mouse is getting moved. As long as the mouse is not moved the event for the click is blocked and not executed. Using this new mode fixes that problem, but we need to handle ‘alt+f4’ on our own. --- v3/pkg/application/application.go | 3 +- v3/pkg/application/webview_window.go | 21 ++++++------- v3/pkg/application/webview_window_windows.go | 32 ++++++++++++++------ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 20f0b30dc..46bab8511 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -767,8 +767,7 @@ func (a *App) runOrDeferToAppRun(r runnable) { } func (a *App) processKeyBinding(acceleratorString string, window *WebviewWindow) bool { - - if a.keyBindings == nil { + if len(a.keyBindings) == 0 { return false } diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index e145d916b..35f3ad5ee 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -1096,20 +1096,17 @@ func (w *WebviewWindow) SetAbsolutePosition(x int, y int) { } func (w *WebviewWindow) processKeyBinding(acceleratorString string) bool { - - if w.keyBindings == nil { - return false - } - // Check key bindings - callback, ok := w.keyBindings[acceleratorString] - if !ok { - return globalApplication.processKeyBinding(acceleratorString, w) - } - // Execute callback - go callback(w) + if w.keyBindings != nil { + if callback := w.keyBindings[acceleratorString]; callback != nil { + // Execute callback + go callback(w) - return true + return true + } + } + + return globalApplication.processKeyBinding(acceleratorString, w) } func (w *WebviewWindow) HandleKeyEvent(acceleratorString string) { diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index bbe99aa12..b53369141 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1289,14 +1289,9 @@ func (w *windowsWebviewWindow) setupChromium() { globalApplication.capabilities = capabilities.NewCapabilities(webview2version) disableFeatues := []string{} - if !opts.EnableFraudulentWebsiteWarnings { disableFeatues = append(disableFeatues, "msSmartScreenProtection") } - - chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath - chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath - if opts.WebviewGpuIsDisabled { chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, "--disable-gpu") } @@ -1306,6 +1301,15 @@ func (w *windowsWebviewWindow) setupChromium() { chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg) } + enableFeatures := []string{"msWebView2BrowserHitTransparent"} + if len(enableFeatures) > 0 { + arg := fmt.Sprintf("--enable-features=%s", strings.Join(enableFeatures, ",")) + chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg) + } + + chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath + chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath + if opts.Permissions != nil { for permission, state := range opts.Permissions { chromium.SetPermission(edge.CoreWebView2PermissionKind(permission), @@ -1547,9 +1551,6 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool { globalApplication.debug("Processing key binding", "vkey", vkey) - if len(w.parent.keyBindings) == 0 { - return false - } // Get the keyboard state and convert to an accelerator var keyState [256]byte if !w32.GetKeyboardState(keyState[:]) { @@ -1584,9 +1585,20 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool { acc.Key = accKey } - // Process the key binding - return w.parent.processKeyBinding(acc.String()) + accKey := acc.String() + globalApplication.debug("Processing key binding", "vkey", vkey, "acc", accKey) + // Process the key binding + if w.parent.processKeyBinding(accKey) { + return true + } + + if accKey == "alt+f4" { + w32.PostMessage(w.hwnd, w32.WM_CLOSE, 0, 0) + return true + } + + return false } func (w *windowsWebviewWindow) processMessageWithAdditionalObjects(message string, sender *edge.ICoreWebView2, args *edge.ICoreWebView2WebMessageReceivedEventArgs) {