Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/webui.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,20 @@ WEBUI_EXPORT size_t webui_get_child_process_id(size_t window);
*/
WEBUI_EXPORT void* webui_win32_get_hwnd(size_t window);

/**
* @brief Get window `HWND`. More reliable with WebView
* than web browser window, as browser PIDs may change on launch.
*
* @param window The window number
*
* @return Returns the window `hwnd` in Win32, `GtkWindow` in Linux.
*
* @example
* HWND hwnd = webui_get_hwnd(myWindow); // Win32 (Work with WebView and web browser)
* GtkWindow* window = webui_get_hwnd(myWindow); // Linux (Work with WebView only)
*/
WEBUI_EXPORT void* webui_get_hwnd(size_t window);

/**
* @brief Get the network port of a running window.
* This can be useful to determine the HTTP link of `webui.js`
Expand Down
32 changes: 32 additions & 0 deletions src/webui.c
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,38 @@ void* webui_win32_get_hwnd(size_t window) {
return NULL;
}

void* webui_get_hwnd(size_t window) {

#ifdef WEBUI_LOG
_webui_log_info("[User] webui_get_hwnd([%zu])\n", window);
#endif

#ifdef _WIN32
return webui_win32_get_hwnd(size_t window);
#elif __linux__

// Initialization
_webui_init();

// Dereference
if (_webui_mutex_app_is_exit_now(WEBUI_MUTEX_GET_STATUS) || _webui.wins[window] == NULL)
return NULL;
_webui_window_t* win = _webui.wins[window];

if (_webui.is_webview) {
if (win->webView) {
return win->webView->gtk_win;
}
}

return NULL;

#else
// macOS
return NULL; // TODO: Return window handler
#endif
}

void webui_set_hide(size_t window, bool status) {

#ifdef WEBUI_LOG
Expand Down
Loading