diff --git a/library/modules/platform/android.sx b/library/modules/platform/android.sx index 2e126c5..c1c5850 100644 --- a/library/modules/platform/android.sx +++ b/library/modules/platform/android.sx @@ -55,6 +55,33 @@ AMotionEvent_getY :: (event: *void, pointer_index: u64) -> f32 #foreig sx_android_query_safe_insets :: (activity: *void, top: *s32, left: *s32, bottom: *s32, right: *s32) -> void #foreign; sx_android_install_input_handler :: (app: *void, handler: (*void, *void) -> s32) -> void #foreign; +// sx-side reimplementation of the JNI dispatch chain inside +// `sx_android_query_safe_insets`. Caller provides an already-attached +// `JNIEnv*` and the activity's `clazz` jobject. Outputs physical-pixel +// insets just like the C foreign helper above. Eventually replaces +// the foreign call once the JavaVM env-attach plumbing has a sx +// equivalent or a thinner C shim. +sx_query_safe_insets_jni :: (env: *void, activity: *void, top: *s32, left: *s32, bottom: *s32, right: *s32) -> void { + inline if OS != .android { return; } + + top.* = 0; left.* = 0; bottom.* = 0; right.* = 0; + if activity == null { return; } + + window := #jni_call(*void)(env, activity, "getWindow", "()Landroid/view/Window;"); + if window == null { return; } + + decor := #jni_call(*void)(env, window, "getDecorView", "()Landroid/view/View;"); + if decor == null { return; } + + insets := #jni_call(*void)(env, decor, "getRootWindowInsets", "()Landroid/view/WindowInsets;"); + if insets == null { return; } + + top.* = #jni_call(s32)(env, insets, "getSystemWindowInsetTop", "()I"); + left.* = #jni_call(s32)(env, insets, "getSystemWindowInsetLeft", "()I"); + bottom.* = #jni_call(s32)(env, insets, "getSystemWindowInsetBottom", "()I"); + right.* = #jni_call(s32)(env, insets, "getSystemWindowInsetRight", "()I"); +} + // EGL — display/surface/context/config are opaque to us. eglGetDisplay :: (display_id: *void) -> *void #foreign; eglInitialize :: (display: *void, major: *s32, minor: *s32) -> u32 #foreign;