summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbandoned Cart <twistedumbrella@gmail.com>2023-06-13 04:17:15 +0200
committerAbandoned Cart <twistedumbrella@gmail.com>2023-06-14 22:35:56 +0200
commit724823c193e9c3aaa630547fc9f5ae562ea33077 (patch)
tree7f28035c09fe4f8f9d480683401968c43055d0e6
parentandroid: Set layout by fragment, not view (diff)
downloadyuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar.gz
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar.bz2
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar.lz
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar.xz
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.tar.zst
yuzu-724823c193e9c3aaa630547fc9f5ae562ea33077.zip
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt5
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt9
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt67
-rw-r--r--src/android/app/src/main/jni/native.cpp13
-rw-r--r--src/android/app/src/main/res/values/integers.xml38
5 files changed, 69 insertions, 63 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
index 4be9ade14..22f0a2646 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
@@ -283,6 +283,11 @@ object NativeLibrary {
external fun isRunning(): Boolean
/**
+ * Returns true if emulation is paused.
+ */
+ external fun isPaused(): Boolean
+
+ /**
* Returns the performance stats for the current game
*/
external fun getPerfStats(): DoubleArray
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 e2eab3105..36cc27a05 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
@@ -271,8 +271,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
val pictureInPictureActions : MutableList<RemoteAction> = mutableListOf()
val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
- val isEmulationPaused = emulationFragment?.isEmulationStatePaused() ?: false
- if (isEmulationPaused) {
+ if (NativeLibrary.isPaused()) {
val playIcon = Icon.createWithResource(this@EmulationActivity, R.drawable.ic_pip_play)
val playPendingIntent = PendingIntent.getBroadcast(
this@EmulationActivity, R.drawable.ic_pip_play, Intent(actionPlay), pendingFlags
@@ -303,9 +302,9 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
private var pictureInPictureReceiver = object : BroadcastReceiver() {
override fun onReceive(context : Context?, intent : Intent) {
if (intent.action == actionPlay) {
- emulationFragment?.onPictureInPicturePlay()
+ if (NativeLibrary.isPaused()) NativeLibrary.unPauseEmulation()
} else if (intent.action == actionPause) {
- emulationFragment?.onPictureInPicturePause()
+ if (!NativeLibrary.isPaused()) NativeLibrary.pauseEmulation()
}
buildPictureInPictureParams()
}
@@ -320,12 +319,10 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
}.also {
registerReceiver(pictureInPictureReceiver, it)
}
- emulationFragment?.onPictureInPictureEnter()
} else {
try {
unregisterReceiver(pictureInPictureReceiver)
} catch (ignored : Exception) { }
- emulationFragment?.onPictureInPictureLeave()
}
}
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
index 5e37db46f..2f1a16f00 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
@@ -77,6 +77,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
emulationActivity = context
NativeLibrary.setEmulationActivity(context)
+ lifecycleScope.launch(Dispatchers.Main) {
+ lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
+ WindowInfoTracker.getOrCreate(context)
+ .windowLayoutInfo(context)
+ .collect { updateFoldableLayout(context, it) }
+ }
+ }
+
onReturnFromSettings = context.activityResultRegistry.register(
"SettingsResult", ActivityResultContracts.StartActivityForResult()
) {
@@ -198,14 +206,28 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
- if (!isInFoldableLayout) {
- if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
- binding.surfaceInputOverlay.setOrientation(InputOverlay.PORTRAIT)
- } else {
- binding.surfaceInputOverlay.setOrientation(InputOverlay.LANDSCAPE)
+ if (emulationActivity?.isInPictureInPictureMode == true) {
+ if (binding.drawerLayout.isOpen) {
+ binding.drawerLayout.close()
+ }
+ if (EmulationMenuSettings.showOverlay) {
+ binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false }
+ }
+ } else {
+ if (EmulationMenuSettings.showOverlay) {
+ binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = true }
+ }
+ if (!isInFoldableLayout) {
+ if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ binding.surfaceInputOverlay.setOrientation(InputOverlay.PORTRAIT)
+ } else {
+ binding.surfaceInputOverlay.setOrientation(InputOverlay.LANDSCAPE)
+ }
+ }
+ if (!binding.surfaceInputOverlay.isInEditMode) {
+ refreshInputOverlay()
}
}
- if (!binding.surfaceInputOverlay.isInEditMode) refreshInputOverlay()
}
override fun onResume() {
@@ -247,37 +269,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
super.onDetach()
}
- fun isEmulationStatePaused() : Boolean {
- return this::emulationState.isInitialized && emulationState.isPaused
- }
-
- fun onPictureInPictureEnter() {
- if (binding.drawerLayout.isOpen) {
- binding.drawerLayout.close()
- }
- if (EmulationMenuSettings.showOverlay) {
- binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false }
- }
- }
-
- fun onPictureInPicturePause() {
- if (!emulationState.isPaused) {
- emulationState.pause()
- }
- }
-
- fun onPictureInPicturePlay() {
- if (emulationState.isPaused) {
- emulationState.run(false)
- }
- }
-
- fun onPictureInPictureLeave() {
- if (EmulationMenuSettings.showOverlay) {
- binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = true }
- }
- }
-
private fun refreshInputOverlay() {
binding.surfaceInputOverlay.refreshControls()
}
@@ -338,7 +329,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt()
- fun updateFoldableLayout(emulationActivity: EmulationActivity, newLayoutInfo: WindowLayoutInfo) {
+ private fun updateFoldableLayout(emulationActivity: EmulationActivity, newLayoutInfo: WindowLayoutInfo) {
val isFolding = (newLayoutInfo.displayFeatures.find { it is FoldingFeature } as? FoldingFeature)?.let {
if (it.isSeparating) {
emulationActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp
index 4091c23d1..f9617202b 100644
--- a/src/android/app/src/main/jni/native.cpp
+++ b/src/android/app/src/main/jni/native.cpp
@@ -202,6 +202,11 @@ public:
return m_is_running;
}
+ bool IsPaused() const {
+ std::scoped_lock lock(m_mutex);
+ return m_is_running && m_is_paused;
+ }
+
const Core::PerfStatsResults& PerfStats() const {
std::scoped_lock m_perf_stats_lock(m_perf_stats_mutex);
return m_perf_stats;
@@ -287,11 +292,13 @@ public:
void PauseEmulation() {
std::scoped_lock lock(m_mutex);
m_system.Pause();
+ m_is_paused = true;
}
void UnPauseEmulation() {
std::scoped_lock lock(m_mutex);
m_system.Run();
+ m_is_paused = false;
}
void HaltEmulation() {
@@ -473,6 +480,7 @@ private:
std::shared_ptr<FileSys::VfsFilesystem> m_vfs;
Core::SystemResultStatus m_load_result{Core::SystemResultStatus::ErrorNotInitialized};
bool m_is_running{};
+ bool m_is_paused{};
SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
std::unique_ptr<Service::Account::ProfileManager> m_profile_manager;
@@ -583,6 +591,11 @@ jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isRunning([[maybe_unused]] JNIEnv
return static_cast<jboolean>(EmulationSession::GetInstance().IsRunning());
}
+jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isPaused([[maybe_unused]] JNIEnv* env,
+ [[maybe_unused]] jclass clazz) {
+ return static_cast<jboolean>(EmulationSession::GetInstance().IsPaused());
+}
+
jboolean Java_org_yuzu_yuzu_1emu_NativeLibrary_isHandheldOnly([[maybe_unused]] JNIEnv* env,
[[maybe_unused]] jclass clazz) {
return EmulationSession::GetInstance().IsHandheldOnly();
diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml
index 04280fae2..2dbe881e3 100644
--- a/src/android/app/src/main/res/values/integers.xml
+++ b/src/android/app/src/main/res/values/integers.xml
@@ -59,43 +59,43 @@
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>
- <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>
+ <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">660</integer>
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>
- <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>
+ <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">320</integer>
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>
<!-- Default SWITCH foldable layout -->
<integer name="SWITCH_BUTTON_A_FOLDABLE_X">840</integer>
- <integer name="SWITCH_BUTTON_A_FOLDABLE_Y">420</integer>
+ <integer name="SWITCH_BUTTON_A_FOLDABLE_Y">340</integer>
<integer name="SWITCH_BUTTON_B_FOLDABLE_X">740</integer>
- <integer name="SWITCH_BUTTON_B_FOLDABLE_Y">460</integer>
+ <integer name="SWITCH_BUTTON_B_FOLDABLE_Y">380</integer>
<integer name="SWITCH_BUTTON_X_FOLDABLE_X">740</integer>
- <integer name="SWITCH_BUTTON_X_FOLDABLE_Y">380</integer>
+ <integer name="SWITCH_BUTTON_X_FOLDABLE_Y">300</integer>
<integer name="SWITCH_BUTTON_Y_FOLDABLE_X">640</integer>
- <integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">420</integer>
+ <integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">340</integer>
<integer name="SWITCH_STICK_L_FOLDABLE_X">180</integer>
- <integer name="SWITCH_STICK_L_FOLDABLE_Y">240</integer>
+ <integer name="SWITCH_STICK_L_FOLDABLE_Y">200</integer>
<integer name="SWITCH_STICK_R_FOLDABLE_X">820</integer>
- <integer name="SWITCH_STICK_R_FOLDABLE_Y">240</integer>
+ <integer name="SWITCH_STICK_R_FOLDABLE_Y">200</integer>
<integer name="SWITCH_TRIGGER_L_FOLDABLE_X">140</integer>
- <integer name="SWITCH_TRIGGER_L_FOLDABLE_Y">100</integer>
+ <integer name="SWITCH_TRIGGER_L_FOLDABLE_Y">80</integer>
<integer name="SWITCH_TRIGGER_R_FOLDABLE_X">860</integer>
- <integer name="SWITCH_TRIGGER_R_FOLDABLE_Y">100</integer>
+ <integer name="SWITCH_TRIGGER_R_FOLDABLE_Y">80</integer>
<integer name="SWITCH_TRIGGER_ZL_FOLDABLE_X">140</integer>
- <integer name="SWITCH_TRIGGER_ZL_FOLDABLE_Y">40</integer>
+ <integer name="SWITCH_TRIGGER_ZL_FOLDABLE_Y">20</integer>
<integer name="SWITCH_TRIGGER_ZR_FOLDABLE_X">860</integer>
- <integer name="SWITCH_TRIGGER_ZR_FOLDABLE_Y">40</integer>
+ <integer name="SWITCH_TRIGGER_ZR_FOLDABLE_Y">20</integer>
<integer name="SWITCH_BUTTON_MINUS_FOLDABLE_X">440</integer>
- <integer name="SWITCH_BUTTON_MINUS_FOLDABLE_Y">550</integer>
+ <integer name="SWITCH_BUTTON_MINUS_FOLDABLE_Y">420</integer>
<integer name="SWITCH_BUTTON_PLUS_FOLDABLE_X">560</integer>
- <integer name="SWITCH_BUTTON_PLUS_FOLDABLE_Y">550</integer>
- <integer name="SWITCH_BUTTON_HOME_FOLDABLE_X">600</integer>
- <integer name="SWITCH_BUTTON_HOME_FOLDABLE_Y">550</integer>
- <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_X">400</integer>
- <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_Y">550</integer>
+ <integer name="SWITCH_BUTTON_PLUS_FOLDABLE_Y">420</integer>
+ <integer name="SWITCH_BUTTON_HOME_FOLDABLE_X">680</integer>
+ <integer name="SWITCH_BUTTON_HOME_FOLDABLE_Y">420</integer>
+ <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_X">320</integer>
+ <integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_Y">420</integer>
<integer name="SWITCH_BUTTON_DPAD_FOLDABLE_X">240</integer>
- <integer name="SWITCH_BUTTON_DPAD_FOLDABLE_Y">420</integer>
+ <integer name="SWITCH_BUTTON_DPAD_FOLDABLE_Y">340</integer>
</resources>