Skip to content

Commit

Permalink
Android: Fix love.window.getSafeArea() not working.
Browse files Browse the repository at this point in the history
Fixes #2081.
  • Loading branch information
MikuAuahDark committed Jun 23, 2024
1 parent 3a31b60 commit 5ee6c5b
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/common/android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,24 @@ bool getSafeArea(int &top, int &left, int &bottom, int &right)
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jobject activity = (jobject) SDL_AndroidGetActivity();
jclass clazz = env->GetObjectClass(activity);
jclass rectClass = env->FindClass("android/graphics/Rect");
jmethodID methodID = env->GetMethodID(clazz, "getSafeArea", "()Landroid/graphics/Rect;");
jobject safeArea = env->CallObjectMethod(activity, methodID);

static jmethodID methodID = env->GetMethodID(clazz, "getSafeArea", "()Z");

bool hasSafeArea = false;

if (methodID == nullptr)
// NoSuchMethodException is thrown in case methodID is null
env->ExceptionClear();
else if ((hasSafeArea = env->CallBooleanMethod(activity, methodID)))
if (safeArea != nullptr)
{
top = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaTop", "I"));
left = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaLeft", "I"));
bottom = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaBottom", "I"));
right = env->GetIntField(activity, env->GetFieldID(clazz, "safeAreaRight", "I"));
top = env->GetIntField(activity, env->GetFieldID(rectClass, "top", "I"));
left = env->GetIntField(activity, env->GetFieldID(rectClass, "left", "I"));
bottom = env->GetIntField(activity, env->GetFieldID(rectClass, "bottom", "I"));
right = env->GetIntField(activity, env->GetFieldID(rectClass, "right", "I"));
env->DeleteLocalRef(safeArea);
}

env->DeleteLocalRef(rectClass);
env->DeleteLocalRef(clazz);
env->DeleteLocalRef(activity);

return hasSafeArea;
return safeArea != nullptr;
}

bool openURL(const std::string &url)
Expand Down

0 comments on commit 5ee6c5b

Please sign in to comment.