Skip to content

Commit 3a45817

Browse files
committed
Add a native handle (like webui_win32_get_hwnd) to get a handle
to the native window on a platform, in order to be able to implement integrations like modal dialogs (open file, save file, choose dir, and dialogs (by opening a new WebView window on top of another, and making it transient or modal for the 'parent'). Signed-off-by: Hans Dijkema <[email protected]>
1 parent 2a9c91c commit 3a45817

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

include/webui.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,24 @@ WEBUI_EXPORT size_t webui_get_child_process_id(size_t window);
901901
*/
902902
WEBUI_EXPORT void* webui_win32_get_hwnd(size_t window);
903903

904+
/**
905+
* @brief Gets the handle to the native window of the specific WebUI implementation
906+
* `GtkWindow *` for the Gtk WebView on Linux, HWND for win32.
907+
* Won't work with a web browser window on Linux, see also webui_win32_gt_hwnd.
908+
*
909+
* @param window The window number
910+
*
911+
* @return Returns the native window handle (`GtkWindow *`, `hwnd`) as `void*`
912+
*
913+
* @example
914+
* #if __linux__
915+
* GtkWindow *w = static_cast<GtkWindow *>(webui_get_native_window_handle_wv(myWindow);
916+
* #elif _WIN32
917+
* HWND h = webui_get_native_window_handle_wv(myWindow);
918+
* #endif
919+
*/
920+
WEBUI_EXPORT void* webui_get_native_window_handle_wv(size_t window);
921+
904922
/**
905923
* @brief Get the network port of a running window.
906924
* This can be useful to determine the HTTP link of `webui.js`

src/webui.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,35 @@ void* webui_win32_get_hwnd(size_t window) {
28002800
return NULL;
28012801
}
28022802

2803+
void* webui_get_native_window_handle_wv(size_t window)
2804+
{
2805+
#ifdef _WIN32
2806+
return webui_win32_get_hwnd(size_t window);
2807+
#elif __linux__
2808+
#ifdef WEBUI_LOG
2809+
_webui_log_info("[User] webui_gtk_get_window_wv([%zu])\n", window);
2810+
#endif
2811+
2812+
// Initialization
2813+
_webui_init();
2814+
2815+
// Dereference
2816+
if (_webui_mutex_app_is_exit_now(WEBUI_MUTEX_GET_STATUS) || _webui.wins[window] == NULL)
2817+
return NULL;
2818+
2819+
_webui_window_t* win = _webui.wins[window];
2820+
2821+
if (_webui.is_webview) {
2822+
return win->webView->gtk_win;
2823+
}
2824+
2825+
return NULL;
2826+
2827+
#else // MACOS
2828+
return NULL; // Don't know how to support on MacOS (yet).
2829+
#endif
2830+
}
2831+
28032832
void webui_set_hide(size_t window, bool status) {
28042833

28052834
#ifdef WEBUI_LOG

0 commit comments

Comments
 (0)