MessageQueue: integrate with glib main loop

Adds a special treatment for the main Looper to not block in java code,
but instead return to glib managed thread loop. Timeouts in the mainloop
are now handled using g_timeout_add_full().

Also defer Activity construction, so that every thing is set up properly
when the constructor runs.
This commit is contained in:
Julian Winkler
2023-08-08 10:16:17 +02:00
parent c6c4e8b3a2
commit 4491de7f63
7 changed files with 80 additions and 29 deletions

View File

@@ -315,7 +315,7 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
free(app_lib_dir);
set_up_handle_cache(env, d->apk_main_activity_class);
set_up_handle_cache(env);
jclass display_class = (*env)->FindClass(env, "android/view/Display");
_SET_STATIC_INT_FIELD(display_class, "window_width", d->window_width);
@@ -329,9 +329,6 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
FIXME__HEIGHT = d->window_height;
window = gtk_application_window_new(app);
(*env)->CallVoidMethod(env, handle_cache.apk_main_activity.object, handle_cache.apk_main_activity.set_window, _INTPTR(window));
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
gtk_window_set_title(GTK_WINDOW(window), "com.example.demo_application");
gtk_window_set_default_size(GTK_WINDOW(window), d->window_width, d->window_height);
@@ -364,6 +361,15 @@ static void open(GtkApplication *app, GFile** files, gint nfiles, const gchar* h
/* extract native libraries from apk*/
extract_from_apk("lib/" NATIVE_ARCH "/", "lib/");
prepare_main_looper(env);
// construct main Activity
handle_cache.apk_main_activity.object = _REF((*env)->CallStaticObjectMethod(env, handle_cache.apk_main_activity.class,
_STATIC_METHOD(handle_cache.apk_main_activity.class, "createMainActivity", "(Ljava/lang/String;J)Landroid/app/Activity;"),
_JSTRING(d->apk_main_activity_class), _INTPTR(window)));
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);
/* -- run the main activity's onCreate -- */
(*env)->CallVoidMethod(env, handle_cache.apk_main_activity.object, handle_cache.apk_main_activity.onCreate, NULL);