From 2f25574bb55bf27b892f869b148ecbf7ad6ccddb Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 22 Oct 2025 12:23:09 +0200 Subject: [PATCH 1/6] With these changes, the navigation eventing works as one would expect it to do. When one calls webui_show* manually all is loaded. Interaction from within the HTML by clicks, javascript, etc. is catched. Signed-off-by: Hans Dijkema --- src/webui.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/webui.c b/src/webui.c index 38944c4ef..741933e2c 100644 --- a/src/webui.c +++ b/src/webui.c @@ -264,6 +264,7 @@ typedef struct webui_event_inf_t { void* gtk_win; void* gtk_wv; bool open; + bool in_show; // WebUI Window char* url; bool navigate; @@ -8175,6 +8176,15 @@ static const char* _webui_get_local_ip(void) { #endif } + +#if __linux__ +#define CHECK_IN_SHOW(win, check) if (win->webView && win->has_all_events) win->webView->in_show = check; +#define IS_IN_SHOW(win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) +#else +#define CHECK_IN_SHOW(win, check) +#define IS_IN_SHOW(win) +#endif + static bool _webui_show_window(_webui_window_t* win, struct mg_connection* client, const char* content, int type, size_t browser) { #ifdef WEBUI_LOG @@ -8188,6 +8198,8 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_log_debug("[Core]\t\t_webui_show_window(FILE, [%zu])\n", browser); #endif + CHECK_IN_SHOW(win, true) + #ifdef WEBUI_TLS // TLS if (_webui_is_empty(_webui.ssl_cert) || _webui_is_empty(_webui.ssl_key)) { @@ -8218,6 +8230,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_free_mem((void*)ssl_cert); _webui_free_mem((void*)ssl_key); WEBUI_ASSERT("Generating self-signed TLS certificate failed"); + CHECK_IN_SHOW(win, false) return false; } @@ -8402,6 +8415,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_free_mem((void*)win->url); _webui_free_port(win->server_port); win->server_port = 0; + CHECK_IN_SHOW(win, false) return false; } } @@ -11878,9 +11892,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { switch(decision_type) { case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: { - webkit_policy_decision_ignore(decision); - _webui_window_t* win = _webui_dereference_win_ptr(user_data); + + if (IS_IN_SHOW(win)) { + CHECK_IN_SHOW(win, false) + return false; + } + + webkit_policy_decision_ignore(decision); + int navigation_type = webkit_navigation_policy_decision_get_navigation_type(decision); void *uri_request = webkit_navigation_policy_decision_get_request(decision); const char *webkit_uri = webkit_uri_request_get_uri(uri_request); @@ -12108,6 +12128,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } // Show + CHECK_IN_SHOW(win, true) webkit_web_view_load_uri(win->webView->gtk_wv, win->webView->url); gtk_widget_show_all(win->webView->gtk_win); win->webView->open = true; From 6a72520158d0fd02e755b1a3bc2806f308194d54 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Wed, 22 Oct 2025 12:27:58 +0200 Subject: [PATCH 2/6] One small addition. bind(, "", ) must have been called to catch all navigation events. Signed-off-by: Hans Dijkema --- src/webui.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/webui.c b/src/webui.c index 741933e2c..b6d637717 100644 --- a/src/webui.c +++ b/src/webui.c @@ -11894,6 +11894,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { _webui_window_t* win = _webui_dereference_win_ptr(user_data); + if (!win->has_all_events) { + return false; + } + if (IS_IN_SHOW(win)) { CHECK_IN_SHOW(win, false) return false; From 777026fa5d236611cba6823c2a22e4c3ffa69488 Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:16:29 -0400 Subject: [PATCH 3/6] Updating code to follow current coding style --- src/webui.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/webui.c b/src/webui.c index b6d637717..d60fbd542 100644 --- a/src/webui.c +++ b/src/webui.c @@ -276,6 +276,10 @@ typedef struct webui_event_inf_t { unsigned int y; bool stop; } _webui_wv_linux_t; + + #define GTK_SET_SHOW (win, status) if (win->webView && win->has_all_events) win->webView->in_show = status; + #define GTK_IS_SHOW (win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) + #else extern bool _webui_macos_wv_new(int index, bool frameless, bool resizable); extern void _webui_macos_wv_new_thread_safe(int index, bool frameless, bool resizable); @@ -8176,15 +8180,6 @@ static const char* _webui_get_local_ip(void) { #endif } - -#if __linux__ -#define CHECK_IN_SHOW(win, check) if (win->webView && win->has_all_events) win->webView->in_show = check; -#define IS_IN_SHOW(win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) -#else -#define CHECK_IN_SHOW(win, check) -#define IS_IN_SHOW(win) -#endif - static bool _webui_show_window(_webui_window_t* win, struct mg_connection* client, const char* content, int type, size_t browser) { #ifdef WEBUI_LOG @@ -8198,8 +8193,6 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_log_debug("[Core]\t\t_webui_show_window(FILE, [%zu])\n", browser); #endif - CHECK_IN_SHOW(win, true) - #ifdef WEBUI_TLS // TLS if (_webui_is_empty(_webui.ssl_cert) || _webui_is_empty(_webui.ssl_key)) { @@ -8230,7 +8223,6 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_free_mem((void*)ssl_cert); _webui_free_mem((void*)ssl_key); WEBUI_ASSERT("Generating self-signed TLS certificate failed"); - CHECK_IN_SHOW(win, false) return false; } @@ -8415,7 +8407,6 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien _webui_free_mem((void*)win->url); _webui_free_port(win->server_port); win->server_port = 0; - CHECK_IN_SHOW(win, false) return false; } } @@ -11863,6 +11854,15 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { #define GTK_RUNTIME_ARR { "libgtk-3.so.0" } // TODO: Add GTK v4 APIs "libgtk-4.so.1" #define WEBKIT_RUNTIME_ARR { "libwebkit2gtk-4.1.so.0", "libwebkit2gtk-4.0.so.37" } + // Decision Event + #define WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION 0 + #define WEBKIT_NAVIGATION_TYPE_LINK_CLICKED 0 + #define WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED 1 + #define WEBKIT_NAVIGATION_TYPE_BACK_FORWARD 2 + #define WEBKIT_NAVIGATION_TYPE_RELOAD 3 + #define WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED 4 + #define WEBKIT_NAVIGATION_TYPE_OTHER 5 + // Title Event static void _webui_wv_event_title(void *web_view, void *pspec, void *arg) { #ifdef WEBUI_LOG @@ -11879,15 +11879,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } } - // Decision Event - #define WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION 0 - #define WEBKIT_NAVIGATION_TYPE_LINK_CLICKED 0 - #define WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED 1 - #define WEBKIT_NAVIGATION_TYPE_BACK_FORWARD 2 - #define WEBKIT_NAVIGATION_TYPE_RELOAD 3 - #define WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED 4 - #define WEBKIT_NAVIGATION_TYPE_OTHER 5 - static bool _webui_wv_event_decision(void *widget, void *decision, int decision_type, void *user_data) { switch(decision_type) { case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: { @@ -11898,8 +11889,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { return false; } - if (IS_IN_SHOW(win)) { - CHECK_IN_SHOW(win, false) + if (GTK_IS_SHOW(win)) { + GTK_SET_SHOW(win, false) return false; } @@ -12132,7 +12123,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } // Show - CHECK_IN_SHOW(win, true) + GTK_SET_SHOW(win, true) // TODO: Check if we need this here because we are about to load a URI webkit_web_view_load_uri(win->webView->gtk_wv, win->webView->url); gtk_widget_show_all(win->webView->gtk_win); win->webView->open = true; @@ -12424,6 +12415,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } } + if (_webui.is_webview) { + // We have a Linux WebKitGTK WebView running + GTK_SET_SHOW(win, true) + } else { + // Failed to start the Linux WebKitGTK + GTK_SET_SHOW(win, false) + } + #ifdef WEBUI_LOG _webui_log_debug("[Core]\t\t_webui_wv_show() -> Return [%d]\n", (_webui.is_webview == true)); #endif From c9449581f53fd6708556da89d5d6dc7b7e7a5543 Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:22:24 -0400 Subject: [PATCH 4/6] Updating code to follow current coding style (adding missing semicolons) --- src/webui.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/webui.c b/src/webui.c index d60fbd542..d4445699b 100644 --- a/src/webui.c +++ b/src/webui.c @@ -277,7 +277,7 @@ typedef struct webui_event_inf_t { bool stop; } _webui_wv_linux_t; - #define GTK_SET_SHOW (win, status) if (win->webView && win->has_all_events) win->webView->in_show = status; + #define GTK_SET_SHOW (win, status) if (win->webView && win->has_all_events) win->webView->in_show = status #define GTK_IS_SHOW (win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) #else @@ -11890,7 +11890,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } if (GTK_IS_SHOW(win)) { - GTK_SET_SHOW(win, false) + GTK_SET_SHOW(win, false); return false; } @@ -12123,7 +12123,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } // Show - GTK_SET_SHOW(win, true) // TODO: Check if we need this here because we are about to load a URI + GTK_SET_SHOW(win, true); // TODO: Check if we need this here because we are about to load a URI webkit_web_view_load_uri(win->webView->gtk_wv, win->webView->url); gtk_widget_show_all(win->webView->gtk_win); win->webView->open = true; @@ -12417,10 +12417,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { if (_webui.is_webview) { // We have a Linux WebKitGTK WebView running - GTK_SET_SHOW(win, true) + GTK_SET_SHOW(win, true); } else { // Failed to start the Linux WebKitGTK - GTK_SET_SHOW(win, false) + GTK_SET_SHOW(win, false); } #ifdef WEBUI_LOG From 8895dd46ec8b7dda4e62bc68cc2bcb052df8f69c Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:26:46 -0400 Subject: [PATCH 5/6] Updating code to follow current coding style (fix macro syntax) --- src/webui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webui.c b/src/webui.c index d4445699b..196eeddb9 100644 --- a/src/webui.c +++ b/src/webui.c @@ -277,8 +277,8 @@ typedef struct webui_event_inf_t { bool stop; } _webui_wv_linux_t; - #define GTK_SET_SHOW (win, status) if (win->webView && win->has_all_events) win->webView->in_show = status - #define GTK_IS_SHOW (win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) + #define GTK_SET_SHOW(win, status) (if (win->webView && win->has_all_events) win->webView->in_show = status) + #define GTK_IS_SHOW(win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) #else extern bool _webui_macos_wv_new(int index, bool frameless, bool resizable); From a4fe620763d7957507d89c3c45ce056b4c2c84f4 Mon Sep 17 00:00:00 2001 From: Showns <116365846+AlbertShown@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:43:54 -0400 Subject: [PATCH 6/6] Updating code to follow current coding style (replace GTK macros with inline functions) --- src/webui.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/webui.c b/src/webui.c index 196eeddb9..4db7447ec 100644 --- a/src/webui.c +++ b/src/webui.c @@ -277,9 +277,6 @@ typedef struct webui_event_inf_t { bool stop; } _webui_wv_linux_t; - #define GTK_SET_SHOW(win, status) (if (win->webView && win->has_all_events) win->webView->in_show = status) - #define GTK_IS_SHOW(win) ((win->webView && win->has_all_events) ? win->webView->in_show : true) - #else extern bool _webui_macos_wv_new(int index, bool frameless, bool resizable); extern void _webui_macos_wv_new_thread_safe(int index, bool frameless, bool resizable); @@ -11879,6 +11876,23 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } } + static inline void _webui_wv_gtk_set_show(_webui_window_t* win, bool status) { + if (win) { + if (win->webView && win->has_all_events) { + win->webView->in_show = status; + } + } + } + + static inline bool _webui_wv_gtk_is_show(_webui_window_t* win) { + if (win) { + if (win->webView && win->has_all_events) { + return win->webView->in_show; + } + } + return true; + } + static bool _webui_wv_event_decision(void *widget, void *decision, int decision_type, void *user_data) { switch(decision_type) { case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: { @@ -11889,8 +11903,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { return false; } - if (GTK_IS_SHOW(win)) { - GTK_SET_SHOW(win, false); + if (_webui_wv_gtk_is_show(win)) { + _webui_wv_gtk_set_show(win, false); return false; } @@ -12123,7 +12137,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { } // Show - GTK_SET_SHOW(win, true); // TODO: Check if we need this here because we are about to load a URI + _webui_wv_gtk_set_show(win, true); // TODO: Check if we need this here because we are about to load a URI webkit_web_view_load_uri(win->webView->gtk_wv, win->webView->url); gtk_widget_show_all(win->webView->gtk_win); win->webView->open = true; @@ -12417,10 +12431,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) { if (_webui.is_webview) { // We have a Linux WebKitGTK WebView running - GTK_SET_SHOW(win, true); + _webui_wv_gtk_set_show(win, true); } else { // Failed to start the Linux WebKitGTK - GTK_SET_SHOW(win, false); + _webui_wv_gtk_set_show(win, false); } #ifdef WEBUI_LOG