diff options
| author | 2023-06-01 17:57:49 -0700 | |
|---|---|---|
| committer | 2023-06-03 00:06:07 -0700 | |
| commit | 057117f0096a47b07f9070d48a0dbd952ab0522e (patch) | |
| tree | b3364fb9ad8e94d16691acc7831d477d975188ff /src/android/app | |
| parent | android: Enable overlay scale/opacity dialog (diff) | |
| download | yuzu-057117f0096a47b07f9070d48a0dbd952ab0522e.tar.gz yuzu-057117f0096a47b07f9070d48a0dbd952ab0522e.tar.xz yuzu-057117f0096a47b07f9070d48a0dbd952ab0522e.zip | |
android: Fix presentation layout on foldable and tablet devices.
Diffstat (limited to 'src/android/app')
4 files changed, 47 insertions, 14 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index abeb01995..81474b824 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt | |||
| @@ -7,6 +7,7 @@ import android.app.Activity | |||
| 7 | import android.content.Context | 7 | import android.content.Context |
| 8 | import android.content.DialogInterface | 8 | import android.content.DialogInterface |
| 9 | import android.content.Intent | 9 | import android.content.Intent |
| 10 | import android.content.res.Configuration | ||
| 10 | import android.graphics.Rect | 11 | import android.graphics.Rect |
| 11 | import android.hardware.Sensor | 12 | import android.hardware.Sensor |
| 12 | import android.hardware.SensorEvent | 13 | import android.hardware.SensorEvent |
| @@ -31,6 +32,7 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings | |||
| 31 | import org.yuzu.yuzu_emu.fragments.EmulationFragment | 32 | import org.yuzu.yuzu_emu.fragments.EmulationFragment |
| 32 | import org.yuzu.yuzu_emu.model.Game | 33 | import org.yuzu.yuzu_emu.model.Game |
| 33 | import org.yuzu.yuzu_emu.utils.ControllerMappingHelper | 34 | import org.yuzu.yuzu_emu.utils.ControllerMappingHelper |
| 35 | import org.yuzu.yuzu_emu.utils.EmulationMenuSettings | ||
| 34 | import org.yuzu.yuzu_emu.utils.ForegroundService | 36 | import org.yuzu.yuzu_emu.utils.ForegroundService |
| 35 | import org.yuzu.yuzu_emu.utils.InputHandler | 37 | import org.yuzu.yuzu_emu.utils.InputHandler |
| 36 | import org.yuzu.yuzu_emu.utils.NfcReader | 38 | import org.yuzu.yuzu_emu.utils.NfcReader |
| @@ -128,6 +130,11 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { | |||
| 128 | super.onResume() | 130 | super.onResume() |
| 129 | nfcReader.startScanning() | 131 | nfcReader.startScanning() |
| 130 | startMotionSensorListener() | 132 | startMotionSensorListener() |
| 133 | |||
| 134 | NativeLibrary.notifyOrientationChange( | ||
| 135 | EmulationMenuSettings.landscapeScreenLayout, | ||
| 136 | getAdjustedRotation() | ||
| 137 | ) | ||
| 131 | } | 138 | } |
| 132 | 139 | ||
| 133 | override fun onPause() { | 140 | override fun onPause() { |
| @@ -233,6 +240,23 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { | |||
| 233 | 240 | ||
| 234 | override fun onAccuracyChanged(sensor: Sensor, i: Int) {} | 241 | override fun onAccuracyChanged(sensor: Sensor, i: Int) {} |
| 235 | 242 | ||
| 243 | private fun getAdjustedRotation():Int { | ||
| 244 | val rotation = windowManager.defaultDisplay.rotation; | ||
| 245 | val config: Configuration = resources.configuration | ||
| 246 | |||
| 247 | if ((config.screenLayout and Configuration.SCREENLAYOUT_LONG_YES) != 0 || | ||
| 248 | (config.screenLayout and Configuration.SCREENLAYOUT_LONG_NO) == 0) { | ||
| 249 | return rotation; | ||
| 250 | } | ||
| 251 | when (rotation) { | ||
| 252 | Surface.ROTATION_0 -> return Surface.ROTATION_90; | ||
| 253 | Surface.ROTATION_90 -> return Surface.ROTATION_0; | ||
| 254 | Surface.ROTATION_180 -> return Surface.ROTATION_270; | ||
| 255 | Surface.ROTATION_270 -> return Surface.ROTATION_180; | ||
| 256 | } | ||
| 257 | return rotation; | ||
| 258 | } | ||
| 259 | |||
| 236 | private fun restoreState(savedInstanceState: Bundle) { | 260 | private fun restoreState(savedInstanceState: Bundle) { |
| 237 | game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!! | 261 | game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!! |
| 238 | } | 262 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt index 783122860..72e2cce2a 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt | |||
| @@ -118,12 +118,6 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView { | |||
| 118 | override fun onStop() { | 118 | override fun onStop() { |
| 119 | super.onStop() | 119 | super.onStop() |
| 120 | presenter.onStop(isFinishing) | 120 | presenter.onStop(isFinishing) |
| 121 | |||
| 122 | // Update framebuffer layout when closing the settings | ||
| 123 | NativeLibrary.notifyOrientationChange( | ||
| 124 | EmulationMenuSettings.landscapeScreenLayout, | ||
| 125 | windowManager.defaultDisplay.rotation | ||
| 126 | ) | ||
| 127 | } | 121 | } |
| 128 | 122 | ||
| 129 | override fun showSettingsFragment(menuTag: String, addToStack: Boolean, gameId: String) { | 123 | override fun showSettingsFragment(menuTag: String, addToStack: Boolean, gameId: String) { |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt index 693e70973..c9f5797ac 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt | |||
| @@ -767,10 +767,11 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context | |||
| 767 | var cutoutBottom = 0 | 767 | var cutoutBottom = 0 |
| 768 | val insets = context.windowManager.currentWindowMetrics.windowInsets.displayCutout | 768 | val insets = context.windowManager.currentWindowMetrics.windowInsets.displayCutout |
| 769 | if (insets != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | 769 | if (insets != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { |
| 770 | maxY = | 770 | if (insets.boundingRectTop.bottom != 0 && insets.boundingRectTop.bottom > maxY / 2) |
| 771 | if (insets.boundingRectTop.bottom != 0) insets.boundingRectTop.bottom.toFloat() else maxY | 771 | insets.boundingRectTop.bottom.toFloat() else maxY |
| 772 | maxX = | 772 | if (insets.boundingRectRight.left != 0 && insets.boundingRectRight.left > maxX / 2) |
| 773 | if (insets.boundingRectRight.left != 0) insets.boundingRectRight.left.toFloat() else maxX | 773 | insets.boundingRectRight.left.toFloat() else maxX |
| 774 | |||
| 774 | minX = insets.boundingRectLeft.right - insets.boundingRectLeft.left | 775 | minX = insets.boundingRectLeft.right - insets.boundingRectLeft.left |
| 775 | minY = insets.boundingRectBottom.top - insets.boundingRectBottom.bottom | 776 | minY = insets.boundingRectBottom.top - insets.boundingRectBottom.bottom |
| 776 | 777 | ||
| @@ -778,7 +779,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context | |||
| 778 | cutoutBottom = insets.boundingRectTop.top - insets.boundingRectTop.bottom | 779 | cutoutBottom = insets.boundingRectTop.top - insets.boundingRectTop.bottom |
| 779 | } | 780 | } |
| 780 | 781 | ||
| 781 | |||
| 782 | // This makes sure that if we have an inset on one side of the screen, we mirror it on | 782 | // This makes sure that if we have an inset on one side of the screen, we mirror it on |
| 783 | // the other side. Since removing space from one of the max values messes with the scale, | 783 | // the other side. Since removing space from one of the max values messes with the scale, |
| 784 | // we also have to account for it using our min values. | 784 | // we also have to account for it using our min values. |
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp index bbe6abdb0..d503ef61d 100644 --- a/src/android/app/src/main/jni/native.cpp +++ b/src/android/app/src/main/jni/native.cpp | |||
| @@ -89,8 +89,16 @@ public: | |||
| 89 | return m_native_window; | 89 | return m_native_window; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | void SetNativeWindow(ANativeWindow* m_native_window_) { | 92 | void SetNativeWindow(ANativeWindow* native_window) { |
| 93 | m_native_window = m_native_window_; | 93 | m_native_window = native_window; |
| 94 | } | ||
| 95 | |||
| 96 | u32 ScreenRotation() const { | ||
| 97 | return m_screen_rotation; | ||
| 98 | } | ||
| 99 | |||
| 100 | void SetScreenRotation(u32 screen_rotation) { | ||
| 101 | m_screen_rotation = screen_rotation; | ||
| 94 | } | 102 | } |
| 95 | 103 | ||
| 96 | void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir, | 104 | void InitializeGpuDriver(const std::string& hook_lib_dir, const std::string& custom_driver_dir, |
| @@ -379,6 +387,7 @@ private: | |||
| 379 | // Window management | 387 | // Window management |
| 380 | std::unique_ptr<EmuWindow_Android> m_window; | 388 | std::unique_ptr<EmuWindow_Android> m_window; |
| 381 | ANativeWindow* m_native_window{}; | 389 | ANativeWindow* m_native_window{}; |
| 390 | u32 m_screen_rotation{}; | ||
| 382 | 391 | ||
| 383 | // Core emulation | 392 | // Core emulation |
| 384 | Core::System m_system; | 393 | Core::System m_system; |
| @@ -404,6 +413,10 @@ private: | |||
| 404 | 413 | ||
| 405 | } // Anonymous namespace | 414 | } // Anonymous namespace |
| 406 | 415 | ||
| 416 | u32 GetAndroidScreenRotation() { | ||
| 417 | return EmulationSession::GetInstance().ScreenRotation(); | ||
| 418 | } | ||
| 419 | |||
| 407 | static Core::SystemResultStatus RunEmulation(const std::string& filepath) { | 420 | static Core::SystemResultStatus RunEmulation(const std::string& filepath) { |
| 408 | Common::Log::Initialize(); | 421 | Common::Log::Initialize(); |
| 409 | Common::Log::SetColorConsoleBackendEnabled(true); | 422 | Common::Log::SetColorConsoleBackendEnabled(true); |
| @@ -450,7 +463,9 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_surfaceDestroyed(JNIEnv* env, | |||
| 450 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_notifyOrientationChange(JNIEnv* env, | 463 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_notifyOrientationChange(JNIEnv* env, |
| 451 | [[maybe_unused]] jclass clazz, | 464 | [[maybe_unused]] jclass clazz, |
| 452 | jint layout_option, | 465 | jint layout_option, |
| 453 | jint rotation) {} | 466 | jint rotation) { |
| 467 | return EmulationSession::GetInstance().SetScreenRotation(static_cast<u32>(rotation)); | ||
| 468 | } | ||
| 454 | 469 | ||
| 455 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env, | 470 | void Java_org_yuzu_yuzu_1emu_NativeLibrary_setAppDirectory(JNIEnv* env, |
| 456 | [[maybe_unused]] jclass clazz, | 471 | [[maybe_unused]] jclass clazz, |