From 7dddb64d928085411ce8e16ecf7d5d25a1739f1e Mon Sep 17 00:00:00 2001 From: Albert Date: Tue, 11 Mar 2025 15:09:13 -0400 Subject: [PATCH] New API - webui_wv_set_headless --- include/webui.h | 10 ++++++++++ src/webui.c | 27 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/webui.h b/include/webui.h index 700e3311..587d6e1c 100644 --- a/include/webui.h +++ b/include/webui.h @@ -874,6 +874,16 @@ WEBUI_EXPORT void webui_set_config(webui_config option, bool status); */ WEBUI_EXPORT void webui_set_event_blocking(size_t window, bool status); +/** + * @brief Make a WebView window headless. + * + * @param window The window number + * @param status The headless status `true` or `false` + * + * @example webui_wv_set_headless(myWindow, true); + */ +WEBUI_EXPORT void webui_wv_set_headless(size_t window, bool status); + /** * @brief Get the HTTP mime type of a file. * diff --git a/src/webui.c b/src/webui.c index 13587b9c..f0484eed 100644 --- a/src/webui.c +++ b/src/webui.c @@ -360,6 +360,7 @@ typedef struct _webui_window_t { bool allow_webview; bool allow_browser; bool update_webview; + bool headless_webview; webui_mutex_t mutex_webview_update; webui_condition_t condition_webview_update; #ifdef _WIN32 @@ -2500,6 +2501,23 @@ void webui_set_config(webui_config option, bool status) { } } +void webui_wv_set_headless(size_t window, bool status) { + + #ifdef WEBUI_LOG + printf("[User] webui_wv_set_headless([%zu], [%d])\n", window, status); + #endif + + // Initialization + _webui_init(); + + // Dereference + if (_webui_mutex_app_is_exit_now(WEBUI_MUTEX_GET_STATUS) || _webui.wins[window] == NULL) + return; + _webui_window_t* win = _webui.wins[window]; + + win->headless_webview = status; +} + void webui_set_event_blocking(size_t window, bool status) { #ifdef WEBUI_LOG printf("[User] webui_set_event_blocking([%zu], [%d])\n", window, status); @@ -11292,8 +11310,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { WEBUI_THREAD_RETURN } + // Set window style based on headless flag + DWORD style = WS_OVERLAPPEDWINDOW; + if (win->headless_webview) { + // Headless mode + style = WS_POPUP | WS_VISIBLE; + } + win->webView->hwnd = CreateWindowExA( - 0, wvClass, "", WS_OVERLAPPEDWINDOW, + 0, wvClass, "", style, win->webView->x, win->webView->y, win->webView->width, win->webView->height, NULL, NULL, GetModuleHandle(NULL), NULL