Remove DisplayHelper class and adjust external display logic

This commit is contained in:
DavidRGriswold 2025-09-20 22:25:27 +03:00 committed by OpenSauce04
parent b0be21beaf
commit 9ddca0118d
4 changed files with 8 additions and 84 deletions

View file

@ -34,7 +34,6 @@ import org.citra.citra_emu.contracts.OpenFileResultContract
import org.citra.citra_emu.databinding.ActivityEmulationBinding
import org.citra.citra_emu.display.ScreenAdjustmentUtil
import org.citra.citra_emu.display.SecondaryDisplay
import org.citra.citra_emu.display.DisplayHelper
import org.citra.citra_emu.features.hotkeys.HotkeyUtility
import org.citra.citra_emu.features.settings.model.BooleanSetting
import org.citra.citra_emu.features.settings.model.IntSetting
@ -86,7 +85,6 @@ class EmulationActivity : AppCompatActivity() {
ThemeUtil.setTheme(this)
settingsViewModel.settings.loadSettings()
super.onCreate(savedInstanceState)
DisplayHelper.checkLaunchDisplay(this)
secondaryDisplay = SecondaryDisplay(this)
secondaryDisplay.updateDisplay()

View file

@ -1,78 +0,0 @@
package org.citra.citra_emu.display
import android.app.Activity
import android.content.Context
import android.hardware.display.DisplayManager
import android.view.Display
import org.citra.citra_emu.features.settings.model.IntSetting
import org.citra.citra_emu.display.SecondaryDisplayLayout
/**
* Utility object that tracks where the application was initially launched and
* provides helper functions to retrieve the logical "internal" and "external"
* displays. If the app was started on an external monitor the roles of the
* displays are swapped so that the secondary presentation always appears on the
* opposite screen.
*/
object DisplayHelper {
private var launchedOnExternal: Boolean? = null
/**
* Inspect the Activity's display on creation and remember if the
* application was launched on an external monitor. This method should be
* called from every Activity's onCreate.
*/
fun checkLaunchDisplay(activity: Activity) {
if (launchedOnExternal == null) {
val displayId = activity.display?.displayId ?: Display.DEFAULT_DISPLAY
launchedOnExternal = displayId != Display.DEFAULT_DISPLAY
}
}
/** Whether the application was initially launched on an external display. */
fun isLaunchedOnExternal(): Boolean = launchedOnExternal == true
private fun getPresentationDisplay(dm: DisplayManager): Display? {
return dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
.firstOrNull { it.displayId != Display.DEFAULT_DISPLAY && it.name != "Built-in Screen" && it.name != "HiddenDisplay" }
}
/**
* Return the display that should be considered the internal one according
* to the launch state.
*/
fun getInternalDisplay(context: Context): Display? {
val dm = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
return if (isLaunchedOnExternal()) {
getPresentationDisplay(dm) ?: dm.getDisplay(Display.DEFAULT_DISPLAY)
} else {
dm.getDisplay(Display.DEFAULT_DISPLAY)
}
}
/**
* Return the display that should be considered the external one according
* to the launch state.
*/
fun getExternalDisplay(context: Context): Display? {
val dm = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
return if (isLaunchedOnExternal()) {
dm.getDisplay(Display.DEFAULT_DISPLAY)
} else {
getPresentationDisplay(dm)
}
}
/**
* Returns true if the primary display is currently showing the 3DS bottom
* screen.
*/
fun isBottomOnPrimary(): Boolean {
val layout = SecondaryDisplayLayout.from(IntSetting.SECONDARY_DISPLAY_LAYOUT.int)
return layout != SecondaryDisplayLayout.BOTTOM_SCREEN &&
layout != SecondaryDisplayLayout.SIDE_BY_SIDE
}
/** Returns true if the secondary presentation hosts the 3DS bottom screen. */
fun isBottomOnSecondary(): Boolean = !isBottomOnPrimary()
}

View file

@ -18,7 +18,6 @@ import android.view.SurfaceView
import android.view.WindowManager
import org.citra.citra_emu.NativeLibrary
import org.citra.citra_emu.features.settings.model.IntSetting
import org.citra.citra_emu.display.DisplayHelper
import org.citra.citra_emu.display.SecondaryDisplayLayout
class SecondaryDisplay(val context: Context) {
@ -45,9 +44,16 @@ class SecondaryDisplay(val context: Context) {
NativeLibrary.secondarySurfaceDestroyed()
}
private fun getExternalDisplay(context: Context): Display? {
val dm = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val internalId = context.display.displayId ?: Display.DEFAULT_DISPLAY
val displays = dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
return displays.firstOrNull { it.displayId != internalId && it.name != "HiddenDisplay" }
}
fun updateDisplay() {
// decide if we are going to the external display or the internal one
var display = DisplayHelper.getExternalDisplay(context)
var display = getExternalDisplay(context)
if (display == null ||
IntSetting.SECONDARY_DISPLAY_LAYOUT.int == SecondaryDisplayLayout.NONE.int) {
display = vd.display

View file

@ -43,7 +43,6 @@ import org.citra.citra_emu.features.settings.model.Settings
import org.citra.citra_emu.features.settings.model.SettingsViewModel
import org.citra.citra_emu.features.settings.ui.SettingsActivity
import org.citra.citra_emu.features.settings.utils.SettingsFile
import org.citra.citra_emu.display.DisplayHelper
import org.citra.citra_emu.fragments.SelectUserDirectoryDialogFragment
import org.citra.citra_emu.fragments.UpdateUserDirectoryDialogFragment
import org.citra.citra_emu.utils.CiaInstallWorker
@ -85,7 +84,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
ThemeUtil.ThemeChangeListener(this)
ThemeUtil.setTheme(this)
super.onCreate(savedInstanceState)
DisplayHelper.checkLaunchDisplay(this)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)