From 820978ec62a4989d95cb0fe88ad8f54eedd749ca Mon Sep 17 00:00:00 2001 From: David Griswold Date: Wed, 17 Sep 2025 21:29:37 +0300 Subject: [PATCH] add quick menu option for secondary layout --- .../citra_emu/display/ScreenAdjustmentUtil.kt | 7 +++ .../citra_emu/fragments/EmulationFragment.kt | 61 +++++++++++++++++++ .../res/drawable/ic_secondary_fit_screen.xml | 13 ++++ .../app/src/main/res/menu/menu_in_game.xml | 5 ++ .../res/menu/menu_secondary_screen_layout.xml | 28 +++++++++ 5 files changed, 114 insertions(+) create mode 100644 src/android/app/src/main/res/drawable/ic_secondary_fit_screen.xml create mode 100644 src/android/app/src/main/res/menu/menu_secondary_screen_layout.xml diff --git a/src/android/app/src/main/java/org/citra/citra_emu/display/ScreenAdjustmentUtil.kt b/src/android/app/src/main/java/org/citra/citra_emu/display/ScreenAdjustmentUtil.kt index e63960fa8..cf18a175c 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/display/ScreenAdjustmentUtil.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/display/ScreenAdjustmentUtil.kt @@ -71,6 +71,13 @@ class ScreenAdjustmentUtil( NativeLibrary.updateFramebuffer(NativeLibrary.isPortraitMode) } + fun changeSecondaryOrientation(layoutOption: Int) { + IntSetting.SECONDARY_DISPLAY_LAYOUT.int = layoutOption + settings.saveSetting(IntSetting.SECONDARY_DISPLAY_LAYOUT,SettingsFile.FILE_NAME_CONFIG) + NativeLibrary.reloadSettings() + NativeLibrary.updateFramebuffer(NativeLibrary.isPortraitMode) + } + fun changeActivityOrientation(orientationOption: Int) { val activity = context as? Activity ?: return IntSetting.ORIENTATION_OPTION.int = orientationOption diff --git a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt index 35899ce7f..07d3e65b5 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/citra/citra_emu/fragments/EmulationFragment.kt @@ -67,6 +67,7 @@ import org.citra.citra_emu.databinding.FragmentEmulationBinding import org.citra.citra_emu.display.PortraitScreenLayout import org.citra.citra_emu.display.ScreenAdjustmentUtil import org.citra.citra_emu.display.ScreenLayout +import org.citra.citra_emu.display.SecondaryDisplayLayout import org.citra.citra_emu.features.settings.model.BooleanSetting import org.citra.citra_emu.features.settings.model.IntSetting import org.citra.citra_emu.features.settings.model.Settings @@ -333,6 +334,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram true } + R.id.menu_secondary_screen_layout -> { + showSecondaryScreenLayoutMenu() + true + } + R.id.menu_swap_screens -> { screenAdjustmentUtil.swapScreen() true @@ -1033,6 +1039,61 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram popupMenu.show() } + private fun showSecondaryScreenLayoutMenu() { + val popupMenu = PopupMenu( + requireContext(), + binding.inGameMenu.findViewById(R.id.menu_secondary_screen_layout) + ) + + popupMenu.menuInflater.inflate(R.menu.menu_secondary_screen_layout, popupMenu.menu) + + val layoutOptionMenuItem = when (IntSetting.SECONDARY_DISPLAY_LAYOUT.int) { + SecondaryDisplayLayout.NONE.int -> + R.id.menu_secondary_layout_none + SecondaryDisplayLayout.REVERSE_PRIMARY.int -> + R.id.menu_secondary_layout_reverse_primary + SecondaryDisplayLayout.TOP_SCREEN.int -> + R.id.menu_secondary_layout_top + SecondaryDisplayLayout.BOTTOM_SCREEN.int -> + R.id.menu_secondary_layout_bottom + else -> + R.id.menu_secondary_layout_side_by_side + + } + + popupMenu.menu.findItem(layoutOptionMenuItem).setChecked(true) + + popupMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.menu_secondary_layout_none -> { + screenAdjustmentUtil.changeSecondaryOrientation(SecondaryDisplayLayout.NONE.int) + true + } + + R.id.menu_secondary_layout_reverse_primary -> { + screenAdjustmentUtil.changeSecondaryOrientation(SecondaryDisplayLayout.REVERSE_PRIMARY.int) + true + } + R.id.menu_secondary_layout_top -> { + screenAdjustmentUtil.changeSecondaryOrientation(SecondaryDisplayLayout.TOP_SCREEN.int) + true + } + R.id.menu_secondary_layout_bottom -> { + screenAdjustmentUtil.changeSecondaryOrientation(SecondaryDisplayLayout.BOTTOM_SCREEN.int) + true + } + R.id.menu_secondary_layout_side_by_side -> { + screenAdjustmentUtil.changeSecondaryOrientation(SecondaryDisplayLayout.SIDE_BY_SIDE.int) + true + } + + + else -> true + } + } + + popupMenu.show() + } private fun editControlsPlacement() { if (binding.surfaceInputOverlay.isInEditMode) { binding.doneControlConfig.visibility = View.GONE diff --git a/src/android/app/src/main/res/drawable/ic_secondary_fit_screen.xml b/src/android/app/src/main/res/drawable/ic_secondary_fit_screen.xml new file mode 100644 index 000000000..3f7d5ac06 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_secondary_fit_screen.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/src/android/app/src/main/res/menu/menu_in_game.xml b/src/android/app/src/main/res/menu/menu_in_game.xml index 950ab6fc8..410c1ddff 100644 --- a/src/android/app/src/main/res/menu/menu_in_game.xml +++ b/src/android/app/src/main/res/menu/menu_in_game.xml @@ -32,6 +32,11 @@ android:icon="@drawable/ic_portrait_fit_screen" android:title="@string/emulation_switch_portrait_layout" /> + + + + + + + + + + + + + + + + + + +