From 50387948dfdc55890aac44c8823a6c41e9ed56bc Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sun, 18 Jun 2023 12:24:44 +1000 Subject: [PATCH] [v3 mac] Refactor drag to use common code --- v3/pkg/application/webview_window_darwin.go | 14 +++++++++++++- v3/pkg/application/webview_window_darwin.h | 1 + v3/pkg/application/webview_window_darwin.m | 20 ++++++-------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 52f6fe376..ade8e7e20 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -818,6 +818,18 @@ static void windowSetFrameless(void *window, bool frameless) { }); } +static void startDrag(void *window) { + dispatch_async(dispatch_get_main_queue(), ^{ + // get main window + WebviewWindow* nsWindow = (WebviewWindow*)window; + + // Get delegate + WebviewWindowDelegate* windowDelegate = (WebviewWindowDelegate*)[nsWindow delegate]; + + // start drag + [windowDelegate startDrag:nsWindow]; + }); +} */ import "C" import ( @@ -1239,6 +1251,6 @@ func (w *macosWebviewWindow) setHTML(html string) { } func (w *macosWebviewWindow) startDrag() error { - // Unused - handled by the native code + C.startDrag(w.nsWindow) return nil } diff --git a/v3/pkg/application/webview_window_darwin.h b/v3/pkg/application/webview_window_darwin.h index af2f146c8..aa67e1c3b 100644 --- a/v3/pkg/application/webview_window_darwin.h +++ b/v3/pkg/application/webview_window_darwin.h @@ -27,6 +27,7 @@ - (void)handleLeftMouseUp:(NSWindow *)window; - (void)handleLeftMouseDown:(NSEvent*)event; +- (void)startDrag:(WebviewWindow*)window; @end diff --git a/v3/pkg/application/webview_window_darwin.m b/v3/pkg/application/webview_window_darwin.m index 77c5496f7..20f3978cd 100644 --- a/v3/pkg/application/webview_window_darwin.m +++ b/v3/pkg/application/webview_window_darwin.m @@ -57,26 +57,18 @@ extern bool hasListeners(unsigned int); self.leftMouseEvent = nil; [super dealloc]; } + +- (void) startDrag:(WebviewWindow*)window { + [window performWindowDragWithEvent:self.leftMouseEvent]; +} + // Handle script messages from the external bridge - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { NSString *m = message.body; - // TODO: Standardise drag by sending the drag event back to Go - if ( [m isEqualToString:@"drag"] ) { - /* - if( [self IsFullScreen] ) { - return; - } - */ - if( self.leftMouseEvent != nil ) { - WKWebView *webView = message.webView; - WebviewWindow *window = (WebviewWindow*)webView.window; - [window performWindowDragWithEvent:self.leftMouseEvent]; - } - return; - } const char *_m = [m UTF8String]; processMessage(self.windowId, _m); } + - (void)handleLeftMouseDown:(NSEvent *)event { self.leftMouseEvent = event; NSWindow *window = [event window];