From e10628f13f87fe3011bc47681622e6a85cf00527 Mon Sep 17 00:00:00 2001 From: zSnails Date: Sat, 22 Feb 2025 13:05:47 -0600 Subject: [PATCH 1/2] feat: add a way of retrieving a native handle of the webview. --- webview.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/webview.go b/webview.go index 7cf0d9f..27efd90 100644 --- a/webview.go +++ b/webview.go @@ -59,6 +59,13 @@ const ( HintMax = C.WEBVIEW_HINT_MAX ) +type NativeHandleKind = C.webview_native_handle_kind_t +const ( + NativeHandleWindow NativeHandleKind = iota + NativeHandleWidget + NativeHandleBrowserController +) + type WebView interface { // Run runs the main loop until it's terminated. After this function exits - @@ -82,6 +89,9 @@ type WebView interface { // NSWindow pointer, when using Win32 backend the pointer is HWND pointer. Window() unsafe.Pointer + // Widget returns a native handle based on the kind requested. + Widget(NativeHandleKind) unsafe.Pointer + // SetTitle updates the title of the native window. Must be called from the UI // thread. SetTitle(title string) @@ -158,6 +168,10 @@ func NewWindow(debug bool, window unsafe.Pointer) WebView { return w } +func (w *webview) Widget(kind NativeHandleKind) unsafe.Pointer { + return C.webview_get_native_handle(w.w, kind) +} + func (w *webview) Destroy() { C.webview_destroy(w.w) } From c905986aabadec0bc123c8af14607bdc6f0702ac Mon Sep 17 00:00:00 2001 From: zSnails Date: Tue, 25 Feb 2025 12:55:31 -0600 Subject: [PATCH 2/2] refactor: rename the function to something more meaningful --- webview.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webview.go b/webview.go index 27efd90..6f57522 100644 --- a/webview.go +++ b/webview.go @@ -89,8 +89,8 @@ type WebView interface { // NSWindow pointer, when using Win32 backend the pointer is HWND pointer. Window() unsafe.Pointer - // Widget returns a native handle based on the kind requested. - Widget(NativeHandleKind) unsafe.Pointer + // NativeHandle returns a native handle based on the kind requested. + NativeHandle(NativeHandleKind) unsafe.Pointer // SetTitle updates the title of the native window. Must be called from the UI // thread. @@ -168,7 +168,7 @@ func NewWindow(debug bool, window unsafe.Pointer) WebView { return w } -func (w *webview) Widget(kind NativeHandleKind) unsafe.Pointer { +func (w *webview) NativeHandle(kind NativeHandleKind) unsafe.Pointer { return C.webview_get_native_handle(w.w, kind) }