fix(ui): apps launched to either screen open where you chose (#3093)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-24 08:11:13 -05:00
1 parent e2d87c5083
commit 46ec222fa5
9 files changed
+108 -18

No files matched your search

@@ -717,6 +717,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
}
}
private var secondScreenDisplays by mutableStateOf<List<SecondScreenDisplay>>(emptyList())
private var ownScreen by mutableStateOf<SecondScreenDisplay?>(null)
private var dualDisplayId by mutableStateOf(-1)
private var dualScreenDevice by mutableStateOf(false)
private var dualScreenMode by mutableStateOf(com.droiddeck.launcher.input.DualScreen.MODE_AUTO)
@@ -1355,6 +1356,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
integrationFocus = integrationFocus,
androidApps = androidApps,
secondScreenDisplays = secondScreenDisplays,
ownScreen = ownScreen,
dualScreen = dualDisplayId >= 0 && com.droiddeck.launcher.ui.DualScreenPanel.available,
dualScreenDevice = dualScreenDevice,
dualScreenMode = dualScreenMode,
@@ -2316,6 +2318,9 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
val ownDisplayId = if (android.os.Build.VERSION.SDK_INT >= 30) display?.displayId ?: android.view.Display.DEFAULT_DISPLAY else @Suppress("DEPRECATION") windowManager.defaultDisplay.displayId
dualScreenMode = SessionPrefs.dualScreenMode(this)
secondScreenDisplays = SecondScreenDisplays.available(displayManager, ownDisplayId)
ownScreen = ownDisplayId.takeIf { it != Display.DEFAULT_DISPLAY }?.let { id ->
displayManager.getDisplay(id)?.takeIf { it.isValid }?.let { SecondScreenDisplay(id, "${it.name} · ${it.mode.physicalWidth}×${it.mode.physicalHeight}") }
}
dualScreenDevice = com.droiddeck.launcher.input.DualScreen.anyDisplay(displayManager, ownDisplayId) != null
dualScreenSessions = SessionPrefs.dualScreenSessionMode(this)
dualScreenControls = SessionPrefs.dualScreenSessionControls(this)
@@ -2336,17 +2341,24 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
private fun launchAndroidApp(app: HomeApp.LaunchableApp, displayId: Int?) {
val onOwnScreen = displayId == null || displayId == (display?.displayId ?: Display.DEFAULT_DISPLAY)
if (onOwnScreen) com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, true)
try {
HomeApp.launch(this, app, displayId)
} catch (_: Exception) {
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
val label = secondScreenDisplays.firstOrNull { it.id == displayId }?.label
val message = when {
displayId == null || displayId == Display.DEFAULT_DISPLAY -> getString(R.string.android_app_open_failed_primary, app.label)
label != null -> getString(R.string.android_app_open_failed_on, app.label, label)
else -> getString(R.string.android_app_open_failed_display, app.label, displayId)
val open = {
try {
HomeApp.launch(this, app, displayId)
} catch (_: Exception) {
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
val label = secondScreenDisplays.firstOrNull { it.id == displayId }?.label
val message = when {
displayId == null || displayId == Display.DEFAULT_DISPLAY -> getString(R.string.android_app_open_failed_primary, app.label)
label != null -> getString(R.string.android_app_open_failed_on, app.label, label)
else -> getString(R.string.android_app_open_failed_display, app.label, displayId)
}
android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_SHORT).show()
}
android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_SHORT).show()
}
if (displayId != null && displayId == com.droiddeck.launcher.ui.DualScreenPanel.shownOn) {
com.droiddeck.launcher.ui.DualScreenPanel.makeRoomForApp(this, displayId, open)
} else {
open()
}
}
@@ -850,8 +850,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
SessionState.bottomMenu = false
SessionState.secondScreenProvisional = false
SessionState.secondScreenAutomatic = false
SessionState.gameOnBottom = false
gameOnBottom = false
SessionState.gameOnBottom = SessionPrefs.dualScreenSessionMode(this) == com.droiddeck.launcher.input.DualScreen.MODE_SWAPPED
gameOnBottom = SessionState.gameOnBottom
}
if (!SessionState.running && SessionState.phase in setOf(SessionPhase.IDLE, SessionPhase.FAILED)) {
SessionState.program = intent.getStringExtra(SessionService.EXTRA_PROGRAM)
@@ -4405,6 +4405,11 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
SessionState.secondScreenAutoOpened = false
val menuOnBottom = drawerDocked
val menuOnTop = drawerOpenState && !drawerDocked
if (mode == com.droiddeck.launcher.input.DualScreen.MODE_SWAPPED) {
putGameOnBottom(true)
} else if (gameOnBottom && mode != com.droiddeck.launcher.input.DualScreen.MODE_OFF) {
putGameOnBottom(false)
}
if (mode == com.droiddeck.launcher.input.DualScreen.MODE_OFF) {
if (gameOnBottom) putGameOnBottom(false)
if (secondScreenMode != SecondScreenMode.NONE || menuOnBottom) closeSecondScreen(reset = true)
@@ -14,7 +14,8 @@ object DualScreen {
const val MODE_AUTO = "auto"
const val MODE_ON = "on"
const val MODE_OFF = "off"
val modes = listOf(MODE_AUTO, MODE_ON, MODE_OFF)
const val MODE_SWAPPED = "swapped"
val modes = listOf(MODE_AUTO, MODE_ON, MODE_SWAPPED, MODE_OFF)
private const val TYPE_INTERNAL = 1
private const val TYPE_EXTERNAL = 2
private val knownModels = setOf("retroid pocket duo", "ayn thor")
@@ -99,7 +100,7 @@ object DualScreen {
fun display(context: Context, displayManager: DisplayManager, primaryDisplayId: Int, mode: String = SessionPrefs.dualScreenMode(context)): Display? =
when (mode) {
MODE_OFF -> null
MODE_ON -> internalDisplay(displayManager, primaryDisplayId) ?: anyDisplay(displayManager, primaryDisplayId)
MODE_ON, MODE_SWAPPED -> internalDisplay(displayManager, primaryDisplayId) ?: anyDisplay(displayManager, primaryDisplayId)
else -> if (dockedToDisplay(displayManager, primaryDisplayId)) null else builtInDisplay(displayManager, primaryDisplayId)
}?.takeUnless { taken(it.displayId) }
@@ -148,7 +148,61 @@ object DualScreenPanel {
}.onFailure { launching = false; displayId = -1 }
}
/**
* The panel on a presentation window sits above every activity on its screen, so an app launched there stays hidden behind it.
* Swapping the panel for a task of its own puts the app above it, and closing the app shows the panel again.
* Launches requested while the swap is under way wait for it and run in the order they were asked for.
*/
fun makeRoomForApp(context: Context, display: Int, launch: () -> Unit) {
pendingLaunches?.let { it.add(launch); return }
val shown = presentation
if (shown == null || displayId != display) { launch(); return }
pendingLaunches = mutableListOf(launch)
val generation = ++handoffGeneration
handoffWaited = 0
presentation = null
shown.dismiss()
launching = true
val intent = Intent(context, DualScreenActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION)
.putExtra(EXTRA_HANDOFF, generation)
val started = runCatching {
context.startActivity(intent, ActivityOptions.makeBasic().setLaunchDisplayId(display).toBundle())
}.isSuccess
if (!started) { launching = false; displayId = -1; releaseLaunches(); return }
handoffPoll.run()
}
private var pendingLaunches: MutableList<() -> Unit>? = null
private var handoffWaited = 0
private var handoffGeneration = 0
internal const val EXTRA_HANDOFF = "handoff"
private val handoffHandler = android.os.Handler(android.os.Looper.getMainLooper())
private val handoffPoll = object : Runnable {
override fun run() {
if (pendingLaunches == null) return
if (activity != null || handoffWaited >= APP_WAIT_MS) releaseLaunches()
else { handoffWaited += APP_POLL_MS; handoffHandler.postDelayed(this, APP_POLL_MS.toLong()) }
}
}
private fun releaseLaunches() {
val waiting = pendingLaunches ?: return
pendingLaunches = null
handoffHandler.removeCallbacks(handoffPoll)
waiting.forEach { it() }
}
private fun dropLaunches() {
pendingLaunches = null
handoffHandler.removeCallbacks(handoffPoll)
}
private const val APP_POLL_MS = 100
private const val APP_WAIT_MS = 2000
fun hide() {
dropLaunches()
stopTyping()
launching = false
displayId = -1
@@ -169,6 +223,9 @@ object DualScreenPanel {
if (activity !== host) activity?.finishAndRemoveTask()
activity = host
launching = false
val waiting = pendingLaunches
val generation = host.intent?.getIntExtra(EXTRA_HANDOFF, -1) ?: -1
handoffHandler.post { if (pendingLaunches === waiting && generation == handoffGeneration) releaseLaunches() }
return true
}
@@ -143,6 +143,7 @@ class FrontEndState(
val integrationFocus: com.droiddeck.launcher.core.SteamIntegration.Feature? = null,
val androidApps: List<HomeApp.LaunchableApp> = emptyList(),
val secondScreenDisplays: List<SecondScreenDisplay> = emptyList(),
val ownScreen: SecondScreenDisplay? = null,
val dualScreen: Boolean = false,
val dualScreenDevice: Boolean = false,
val dualScreenMode: String = com.droiddeck.launcher.input.DualScreen.MODE_AUTO,
@@ -802,7 +803,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
},
{ selected = it },
onAndroidAppClick = { app ->
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
if (s.secondScreenDisplays.isEmpty() && s.ownScreen == null) a.onAndroidApp(app, null)
else appToChooseDisplay = app
},
onOpenDeveloperOptions = requestChildProcessToggle,
@@ -823,7 +824,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
SessionDrawerPreview(s.secondScreenDisplays)
appToChooseDisplay?.let { app ->
val secondaryDisplay = s.secondScreenDisplays.firstOrNull()
val secondaryDisplay = s.secondScreenDisplays.firstOrNull() ?: s.ownScreen
ChooseAppDisplayDialog(
app = app,
secondaryDisplay = secondaryDisplay,
@@ -542,7 +542,7 @@ internal fun SetupPanel(
)
ChoiceRow(
host, "dual-screen-sessions", stringResource(R.string.setup_dual_screen_sessions), stringResource(R.string.setup_dual_screen_sessions_hint),
dualModes, s.dualScreenSessions, onPick = a.onDualScreenSessions,
dualModes.take(2) + (com.droiddeck.launcher.input.DualScreen.MODE_SWAPPED to stringResource(R.string.setup_dual_screen_swapped)) + dualModes.drop(2), s.dualScreenSessions, onPick = a.onDualScreenSessions,
)
if (s.dualScreenSessions != com.droiddeck.launcher.input.DualScreen.MODE_OFF) {
ToggleRow(host, "dual-screen-controls", stringResource(R.string.setup_dual_screen_controls),
@@ -1519,6 +1519,7 @@ private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String)
listOf(
com.droiddeck.launcher.input.DualScreen.MODE_AUTO to stringResource(R.string.setup_dual_screen_auto),
com.droiddeck.launcher.input.DualScreen.MODE_ON to stringResource(R.string.setup_dual_screen_on),
com.droiddeck.launcher.input.DualScreen.MODE_SWAPPED to stringResource(R.string.setup_dual_screen_swapped),
com.droiddeck.launcher.input.DualScreen.MODE_OFF to stringResource(R.string.setup_dual_screen_off),
), a.dualScreenMode, chipModifier = track("dual-screen-mode"), onPick = a.onDualScreenMode)
if (swapsGame) ChoiceRow(host, "game-screen", stringResource(R.string.swap_game_screen), null,
+2 -1
View File
@@ -1041,10 +1041,11 @@
<string name="setup_dual_screen_launcher">Dual screen launcher</string>
<string name="setup_dual_screen_launcher_hint">Automatic puts the launcher sections (Steam, Library, Stores and the rest) on the second screen of handhelds with a built-in one. On uses any second display. Off keeps the launcher on one screen.</string>
<string name="setup_dual_screen_sessions">Dual screen sessions</string>
<string name="setup_dual_screen_sessions_hint">Automatic docks the in-game menu on the built-in second screen instead of a pop-over. On uses any second display. Off keeps the menu on the game screen; you can still pick a second screen from it.</string>
<string name="setup_dual_screen_sessions_hint">Automatic docks the in-game menu on the built-in second screen instead of a pop-over. On uses any second display. On, game on second screen runs the game there and keeps the menu and controls on this screen, for a phone driving a monitor or TV. Off keeps the menu on the game screen; you can still pick a second screen from it.</string>
<string name="setup_dual_screen_auto">Automatic</string>
<string name="setup_dual_screen_on">On</string>
<string name="setup_dual_screen_off">Off</string>
<string name="setup_dual_screen_swapped">On, game on second screen</string>
<string name="setup_dual_screen_controls">Bottom screen controls in games</string>
<string name="setup_android_text_field_keyboard">Android keyboard for text fields</string>
<string name="setup_dual_screen_controls_hint">Opens a panel on the second screen when a session starts: the Deck buttons and trackpads with a Steam Deck or Steam Controller, otherwise the one you used last.</string>