From 6ba6ea2db7f99f805012dfa77947e4d07b908a09 Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Tue, 7 Sep 2021 19:32:57 +0200 Subject: [PATCH] Fix offset on-screen controls on desktop mode. --- .../net/kdt/pojavlaunch/PojavLauncherActivity.java | 1 + .../src/main/java/net/kdt/pojavlaunch/Tools.java | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java index ce17fbea3..bc6037f5d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/PojavLauncherActivity.java @@ -317,6 +317,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity PREF_NOTCH_SIZE = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout().getBoundingRects().get(0).width(); }catch (Exception e){ Log.i("NOTCH DETECTION", "No notch detected, or the device if in split screen mode"); + PREF_NOTCH_SIZE = -1; } Tools.updateWindowSize(this); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index a19904931..dfa198dfb 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -29,7 +29,9 @@ import org.lwjgl.glfw.*; import android.view.*; import android.widget.Toast; +import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.P; +import static android.os.Build.VERSION_CODES.Q; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE; @@ -79,7 +81,7 @@ public final class Tools { public static void initContextConstants(Context ctx){ DIR_DATA = ctx.getFilesDir().getParent(); MULTIRT_HOME = DIR_DATA+"/runtimes"; - if(Build.VERSION.SDK_INT >= 29) { + if(SDK_INT >= 29) { DIR_GAME_HOME = ctx.getExternalFilesDir(null).getAbsolutePath(); }else{ DIR_GAME_HOME = new File(Environment.getExternalStorageDirectory(),"games/PojavLauncher").getAbsolutePath(); @@ -338,11 +340,12 @@ public final class Tools { public static DisplayMetrics getDisplayMetrics(Activity ctx) { DisplayMetrics displayMetrics = new DisplayMetrics(); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (ctx.isInMultiWindowMode() || ctx.isInPictureInPictureMode())){ + if(SDK_INT >= Build.VERSION_CODES.N && (ctx.isInMultiWindowMode() || ctx.isInPictureInPictureMode()) + || PREF_NOTCH_SIZE == -1 ){ //For devices with free form/split screen, we need window size, not screen size. displayMetrics = ctx.getResources().getDisplayMetrics(); }else{ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (SDK_INT >= Build.VERSION_CODES.R) { ctx.getDisplay().getRealMetrics(displayMetrics); } else { ctx.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics); @@ -828,7 +831,7 @@ public final class Tools { } public static void ignoreNotch(boolean shouldIgnore, Activity ctx){ - if (Build.VERSION.SDK_INT >= P) { + if (SDK_INT >= P) { if (shouldIgnore) { ctx.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; } else {