@@ -202,25 +202,31 @@ typedef struct webui_event_inf_t {
202202#elif __linux__
203203 void * libgtk ;
204204 void * libwebkit ;
205- // GTK Symbol Addresses
206- typedef void * (* gtk_init_func )(int * argc , char * * * argv );
207- typedef void (* gtk_widget_show_all_func )(void * );
208- typedef void (* gtk_main_iteration_do_func )(int );
209- typedef int (* gtk_events_pending_func )(void );
210- typedef void (* gtk_container_add_func )(void * , void * );
211- typedef void * (* gtk_window_new_func )(int );
205+ // GTK Symbol Definition
206+ typedef void * (* gtk_init_func )(int * argc , char * * * argv ); // Ini
207+ typedef void (* gtk_widget_show_all_func )(void * ); // Show
208+ typedef int (* gtk_main_iteration_do_func )(int ); // Last UI draw when exit
209+ typedef int (* gtk_events_pending_func )(void ); // Last UI draw when exit
210+ typedef void * (* gtk_main_func )(void ); // Main loop
211+ typedef void * (* gtk_main_quit_func )(void ); // Exit main loop
212+ typedef int (* g_timeout_add_func )(int , int (* function )(void * ), void * ); // WebUI exit loop
213+ typedef void (* gtk_container_add_func )(void * , void * ); // WebView Container
214+ typedef void * (* gtk_window_new_func )(int ); // New Window
215+ typedef int (* g_idle_add_func )(int (* function )(void * ), void * ); // New Window creation schedule
212216 typedef void (* gtk_window_set_default_size_func )(void * , int , int );
213217 typedef void (* gtk_window_set_title_func )(void * , const char * );
214218 typedef void (* gtk_window_move_func )(void * , int , int );
215219 typedef void (* gtk_window_close_func )(void * );
216220 typedef void (* gtk_window_resize_func )(void * , int , int );
217221 typedef void (* gtk_window_set_position_func )(void * , int );
218- typedef int (* g_idle_add_func )(int (* function )(void * ), void * );
219- typedef void (* g_signal_connect_data_func )(void * , const char * ,
220- void (* callback )(void ), void * , void * , int );
222+ typedef unsigned long (* g_signal_connect_data_func )(void * , const char * , void (* callback )(void ), void * , void * , int );
223+ // GTK Symbol Initialization
221224 gtk_init_func gtk_init = NULL ;
222225 gtk_widget_show_all_func gtk_widget_show_all = NULL ;
223226 gtk_main_iteration_do_func gtk_main_iteration_do = NULL ;
227+ gtk_main_func gtk_main = NULL ;
228+ gtk_main_quit_func gtk_main_quit = NULL ;
229+ g_timeout_add_func g_timeout_add = NULL ;
224230 gtk_events_pending_func gtk_events_pending = NULL ;
225231 gtk_container_add_func gtk_container_add = NULL ;
226232 gtk_window_new_func gtk_window_new = NULL ;
@@ -617,6 +623,7 @@ static bool _webui_wv_set_position(_webui_wv_linux_t* webView, int x, int y);
617623static bool _webui_wv_set_size (_webui_wv_linux_t * webView , int windowWidth , int windowHeight );
618624static bool _webui_wv_show (_webui_window_t * win , char * url );
619625static void _webui_wv_event_closed (void * widget , void * arg );
626+ static int _webui_wv_exit_schedule (void * arg );
620627#else
621628// macOS
622629static void _webui_wv_free (_webui_wv_macos_t * webView );
@@ -3275,15 +3282,8 @@ void webui_wait(void) {
32753282
32763283 _webui .is_gtk_main_run = true;
32773284
3278- while (true) {
3279-
3280- while (gtk_events_pending ()) {
3281- gtk_main_iteration_do (0 );
3282- }
3283-
3284- if (_webui_mutex_app_is_exit_now (WEBUI_MUTEX_GET_STATUS ))
3285- break ;
3286- }
3285+ // GTK Run Application
3286+ gtk_main ();
32873287
32883288 _webui .is_gtk_main_run = false;
32893289 }
@@ -11319,8 +11319,8 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1131911319 }
1132011320
1132111321 _webui .is_webview = false;
11322- libgtk = NULL ;
1132311322 libwebkit = NULL ;
11323+ libgtk = NULL ;
1132411324 };
1132511325
1132611326 static void _webui_wv_create (_webui_window_t * win ) {
@@ -11377,6 +11377,9 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1137711377 pthread_create (& thread , NULL , & _webui_webview_thread , (void * )win );
1137811378 pthread_detach (thread );
1137911379 #endif
11380+
11381+ // WebUI Exit Event for GTK
11382+ g_timeout_add ((1 * 1000 ), _webui_wv_exit_schedule , NULL );
1138011383 }
1138111384
1138211385 static int _webui_wv_create_schedule (void * arg ) {
@@ -11396,6 +11399,24 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1139611399 return 0 ;
1139711400 }
1139811401
11402+ static int _webui_wv_exit_schedule (void * arg ) {
11403+
11404+ #ifdef WEBUI_LOG
11405+ // printf("[Core]\t\t_webui_wv_exit_schedule()\n");
11406+ #endif
11407+
11408+ if (_webui_mutex_app_is_exit_now (WEBUI_MUTEX_GET_STATUS )) {
11409+ if (_webui .is_gtk_main_run ) {
11410+ #ifdef WEBUI_LOG
11411+ printf ("[Core]\t\t_webui_wv_exit_schedule() -> Quit GTK Main Loop...\n" );
11412+ #endif
11413+ gtk_main_quit ();
11414+ }
11415+ return 0 ;
11416+ }
11417+ return 1 ;
11418+ }
11419+
1139911420 static bool _webui_wv_show (_webui_window_t * win , char * url ) {
1140011421
1140111422 #ifdef WEBUI_LOG
@@ -11462,6 +11483,12 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1146211483 libgtk , "gtk_widget_show_all" );
1146311484 gtk_main_iteration_do = (gtk_main_iteration_do_func )dlsym (
1146411485 libgtk , "gtk_main_iteration_do" );
11486+ gtk_main = (gtk_main_func )dlsym (
11487+ libgtk , "gtk_main" );
11488+ gtk_main_quit = (gtk_main_quit_func )dlsym (
11489+ libgtk , "gtk_main_quit" );
11490+ g_timeout_add = (g_timeout_add_func )dlsym (
11491+ libgtk , "g_timeout_add" );
1146511492 gtk_events_pending = (gtk_events_pending_func )dlsym (
1146611493 libgtk , "gtk_events_pending" );
1146711494 gtk_container_add = (gtk_container_add_func )dlsym (
@@ -11495,12 +11522,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1149511522
1149611523 // Check GTK
1149711524 if (
11498- // GTK Commun
11499- !gtk_init || !gtk_window_new || !gtk_window_set_default_size
11500- || !gtk_window_set_title || !g_signal_connect_data
1150111525 // GTK v3
11502- || !gtk_widget_show_all || !gtk_main_iteration_do
11503- || !gtk_events_pending || !gtk_container_add
11526+ !gtk_init || !gtk_window_new || !gtk_window_set_default_size
11527+ || !gtk_window_set_title || !g_signal_connect_data || !gtk_main
11528+ || !gtk_main_quit || !gtk_widget_show_all || !gtk_main_iteration_do
11529+ || !g_timeout_add || !gtk_events_pending || !gtk_container_add
1150411530 || !gtk_window_move
1150511531 // GTK v4
1150611532 // ...
@@ -11563,10 +11589,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved) {
1156311589 // from this thread, which is should be fired from
1156411590 // the back-end main thread.
1156511591
11566- #ifdef WEBUI_LOG
11567- printf ("[Core]\t\t_webui_wv_show() -> New WebView window\n" );
11568- #endif
11569-
1157011592 _webui_wv_create (win );
1157111593 }
1157211594
0 commit comments