|
49 | 49 | #include <android_native_app_glue.h> // Required for: android_app struct and activity management
|
50 | 50 | #include <android/window.h> // Required for: AWINDOW_FLAG_FULLSCREEN definition and others
|
51 | 51 | //#include <android/sensor.h> // Required for: Android sensors functions (accelerometer, gyroscope, light...)
|
52 |
| -#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL()] |
| 52 | +#include <jni.h> // Required for: JNIEnv and JavaVM [Used in OpenURL() and GetCurrentMonitor()] |
53 | 53 |
|
54 | 54 | #include <EGL/egl.h> // Native platform windowing system interface
|
55 | 55 |
|
@@ -446,8 +446,32 @@ int GetMonitorCount(void)
|
446 | 446 | // Get current monitor where window is placed
|
447 | 447 | int GetCurrentMonitor(void)
|
448 | 448 | {
|
449 |
| - TRACELOG(LOG_WARNING, "GetCurrentMonitor() not implemented on target platform"); |
450 |
| - return 0; |
| 449 | + int displayId = -1; |
| 450 | + JNIEnv* env = NULL; |
| 451 | + JavaVM* vm = platform.app->activity->vm; |
| 452 | + (*vm)->AttachCurrentThread(vm, &env, NULL); |
| 453 | + |
| 454 | + jobject activity = platform.app->activity->clazz; |
| 455 | + jclass activityClass = (*env)->GetObjectClass(env, activity); |
| 456 | + |
| 457 | + jmethodID getDisplayMethod = (*env)->GetMethodID(env, activityClass, "getDisplay", "()Landroid/view/Display;"); |
| 458 | + |
| 459 | + jobject display = (*env)->CallObjectMethod(env, activity, getDisplayMethod); |
| 460 | + |
| 461 | + if (display == NULL) { |
| 462 | + TRACELOG(LOG_ERROR, "GetCurrentMonitor() couldn't get the display object"); |
| 463 | + } else { |
| 464 | + jclass displayClass = (*env)->FindClass(env, "android/view/Display"); |
| 465 | + jmethodID getDisplayIdMethod = (*env)->GetMethodID(env, displayClass, "getDisplayId", "()I"); |
| 466 | + displayId = (int) (*env)->CallIntMethod(env, display, getDisplayIdMethod); |
| 467 | + (*env)->DeleteLocalRef(env, displayClass); |
| 468 | + } |
| 469 | + |
| 470 | + (*env)->DeleteLocalRef(env, activityClass); |
| 471 | + (*env)->DeleteLocalRef(env, display); |
| 472 | + |
| 473 | + (*vm)->DetachCurrentThread(vm); |
| 474 | + return displayId; |
451 | 475 | }
|
452 | 476 |
|
453 | 477 | // Get selected monitor position
|
|
0 commit comments