Browse Source

[rcore_android] implement GetCurrentMonitor() (#5204)

pull/5205/head
Keks137 2 weeks ago
committed by GitHub
parent
commit
3f6d67c61c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 3 deletions
  1. +27
    -3
      src/platforms/rcore_android.c

+ 27
- 3
src/platforms/rcore_android.c View File

@ -49,7 +49,7 @@
#include <android_native_app_glue.h> // Required for: android_app struct and activity management
#include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
//#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL()]
#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL() and GetCurrentMonitor()]
#include <EGL/egl.h> // Native platform windowing system interface
@ -446,8 +446,32 @@ int GetMonitorCount(void)
// Get current monitor where window is placed
int GetCurrentMonitor(void)
{
TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform");
return 0;
int displayId = -1;
JNIEnv* env = NULL;
JavaVM* vm = platform.app->activity->vm;
(*vm)->AttachCurrentThread(vm, &env, NULL);
jobject activity = platform.app->activity->clazz;
jclass activityClass = (*env)->GetObjectClass(env, activity);
jmethodID getDisplayMethod = (*env)->GetMethodID(env, activityClass, "getDisplay", "()Landroid/view/Display;");
jobject display = (*env)->CallObjectMethod(env, activity, getDisplayMethod);
if (display == NULL) {
TRACELOG(LOG_ERROR, "GetCurrentMonitor() couldn't get the display object");
} else {
jclass displayClass = (*env)->FindClass(env, "android/view/Display");
jmethodID getDisplayIdMethod = (*env)->GetMethodID(env, displayClass, "getDisplayId", "()I");
displayId = (int) (*env)->CallIntMethod(env, display, getDisplayIdMethod);
(*env)->DeleteLocalRef(env, displayClass);
}
(*env)->DeleteLocalRef(env, activityClass);
(*env)->DeleteLocalRef(env, display);
(*vm)->DetachCurrentThread(vm);
return displayId;
}
// Get selected monitor position

Loading…
Cancel
Save