add support for the boneheaded method of receiving input events that is used by NativeActivity apps

currently, our "not-actually-a-queue" implementation is quite ugly,
hopefully it might be possible to make it look somewhat sane while
not needing to make it as much of a queue as it is on android
This commit is contained in:
Mis012
2022-11-11 19:18:21 +01:00
parent 231ac88dbd
commit 33b4515cb9
12 changed files with 291 additions and 36 deletions

View File

@@ -544,20 +544,19 @@ Java_android_app_NativeActivity_onSurfaceDestroyedNative(JNIEnv* env, jobject cl
}
void
Java_android_app_NativeActivity_onInputQueueCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jint queuePtr)
Java_android_app_NativeActivity_onInputQueueCreatedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queue)
{
printf("STUB - onInputChannelCreated_native\n");
/* if (handle != 0) {
if (handle != 0) {
struct NativeCode* code = (struct NativeCode*)handle;
if (code->callbacks.onInputQueueCreated != NULL) {
AInputQueue* queue = reinterpret_cast<AInputQueue*>(queuePtr);
code->callbacks.onInputQueueCreated(code, queue);
}
}*/
}
}
void
Java_android_app_NativeActivity_onInputQueueDestroyedNative(JNIEnv* env, jobject clazz, jlong handle, jint queuePtr)
Java_android_app_NativeActivity_onInputQueueDestroyedNative(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
{
printf("STUB - onInputChannelDestroyed_native\n");
/* if (handle != 0) {

View File

@@ -9,3 +9,18 @@ JNIEXPORT void JNICALL Java_android_view_Window_set_1widget_1as_1root(JNIEnv *en
{
gtk_window_set_child(GTK_WINDOW(_PTR(window)), gtk_widget_get_parent(GTK_WIDGET(_PTR(widget))));
}
JNIEXPORT void JNICALL Java_android_view_Window_take_1input_1queue(JNIEnv *env, jobject this, jlong native_window, jobject callback, jobject queue)
{
GtkWidget *window = _PTR(native_window);
printf("in Java_android_view_Window_take_1input_1queue\n");
GtkEventController *controller = GTK_EVENT_CONTROLLER(gtk_event_controller_legacy_new());
gtk_widget_add_controller(window, controller);
_SET_LONG_FIELD(queue, "native_ptr", _INTPTR(controller));
// we need to keep these for later, so they can be called after OnCreate finishes
g_object_set_data(G_OBJECT(window), "input_queue_callback", (gpointer)_REF(callback));
g_object_set_data(G_OBJECT(window), "input_queue", (gpointer)_REF(queue));
}

View File

@@ -122,18 +122,18 @@ JNIEXPORT void JNICALL Java_android_app_NativeActivity_onSurfaceDestroyedNative
/*
* Class: android_app_NativeActivity
* Method: onInputQueueCreatedNative
* Signature: (JI)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_app_NativeActivity_onInputQueueCreatedNative
(JNIEnv *, jobject, jlong, jint);
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_app_NativeActivity
* Method: onInputQueueDestroyedNative
* Signature: (JI)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_app_NativeActivity_onInputQueueDestroyedNative
(JNIEnv *, jobject, jlong, jint);
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_app_NativeActivity

View File

@@ -15,6 +15,14 @@ extern "C" {
JNIEXPORT void JNICALL Java_android_view_Window_set_1widget_1as_1root
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_Window
* Method: take_input_queue
* Signature: (JLandroid/view/InputQueue/Callback;Landroid/view/InputQueue;)V
*/
JNIEXPORT void JNICALL Java_android_view_Window_take_1input_1queue
(JNIEnv *, jobject, jlong, jobject, jobject);
#ifdef __cplusplus
}
#endif

View File

@@ -68,6 +68,9 @@ void set_up_handle_cache(JNIEnv *env, char *apk_main_activity_class)
handle_cache.audio_track_periodic_listener.class = _REF((*env)->FindClass(env, "android/media/AudioTrack$OnPlaybackPositionUpdateListener"));
handle_cache.audio_track_periodic_listener.onPeriodicNotification = _METHOD(handle_cache.audio_track_periodic_listener.class, "onPeriodicNotification", "(Landroid/media/AudioTrack;)V");
handle_cache.input_queue_callback.class = _REF((*env)->FindClass(env, "android/view/InputQueue$Callback"));
handle_cache.input_queue_callback.onInputQueueCreated = _METHOD(handle_cache.input_queue_callback.class, "onInputQueueCreated", "(Landroid/view/InputQueue;)V");
handle_cache.view.class = _REF((*env)->FindClass(env, "android/view/View"));
if((*env)->ExceptionCheck(env))
(*env)->ExceptionDescribe(env);

View File

@@ -57,6 +57,10 @@ struct handle_cache {
jclass class;
jmethodID onPeriodicNotification;
} audio_track_periodic_listener;
struct {
jclass class;
jmethodID onInputQueueCreated;
} input_queue_callback;
struct {
jclass class;
jmethodID setLayoutParams;