fix: opening DroidDeck from iisu on the AYN Thor no longer bounces back (#1901)

This commit is contained in:
0x142857 authored and GitHub committed 2026-10-31 23:33:40 -04:00
1 parent 2ff3ab447d
commit 85c41f9032
2 files changed
+130 -4

No files matched your search

@@ -64,10 +64,12 @@ class DualPanelModel(
object DualScreenPanel {
var model by mutableStateOf<DualPanelModel?>(null)
private var displayId = -1
private var presentation: DualScreenPresentation? = null
set(value) { field = value; available = value != null || activity != null || launching }
private var activity: DualScreenActivity? = null
set(value) { field = value; available = value != null || launching }
set(value) { field = value; available = value != null || presentation != null || launching }
private var launching = false
set(value) { field = value; available = value || activity != null }
set(value) { field = value; available = value || activity != null || presentation != null }
private var ownerTask = -1
private var ownerYielded = false
private var ownerPaused = false
@@ -77,8 +79,8 @@ object DualScreenPanel {
var typingShown by mutableStateOf(false)
private set
val shownOn: Int get() = if (activity != null || launching) displayId else -1
val attached: Boolean get() = activity != null
val shownOn: Int get() = if (presentation != null || activity != null || launching) displayId else -1
val attached: Boolean get() = presentation != null || activity != null
var available by mutableStateOf(false)
private set
@@ -123,6 +125,20 @@ object DualScreenPanel {
ownerYielded = false
ownerPaused = false
launching = true
val host = context as? ComponentActivity
val target = host?.getSystemService(Context.DISPLAY_SERVICE)
?.let { (it as android.hardware.display.DisplayManager).getDisplay(display) }
// A second-display activity makes the system launcher treat its bottom home as lost and bring itself forward;
// a presentation belongs to this task and leaves that home alone.
if (host != null && target != null) {
val shown = runCatching { DualScreenPresentation(host, target).also { it.show() } }
if (shown.isSuccess) {
presentation = shown.getOrThrow()
launching = false
return
}
android.util.Log.w("DualScreenPanel", "bottom panel presentation failed; falling back to an activity", shown.exceptionOrNull())
}
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)
runCatching {
@@ -134,6 +150,8 @@ object DualScreenPanel {
stopTyping()
launching = false
displayId = -1
presentation?.dismiss()
presentation = null
activity?.finishAndRemoveTask()
activity = null
}
@@ -144,6 +162,8 @@ object DualScreenPanel {
internal fun attach(host: DualScreenActivity): Boolean {
if (!launching && activity == null) return false
presentation?.dismiss()
presentation = null
if (activity !== host) activity?.finishAndRemoveTask()
activity = host
launching = false
@@ -188,6 +208,13 @@ object DualScreenPanel {
displayId = -1
}
}
internal fun detach(host: DualScreenPresentation) {
if (presentation === host) {
presentation = null
displayId = -1
}
}
}
class DualScreenActivity : ComponentActivity() {
@@ -0,0 +1,99 @@
package com.droiddeck.launcher.ui
import android.app.Presentation
import android.os.Bundle
import android.view.Display
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.setViewTreeOnBackPressedDispatcherOwner
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeViewModelStoreOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.droiddeck.launcher.core.AppUiPrefs
internal class DualScreenPresentation(
private val host: ComponentActivity,
display: Display,
) : Presentation(host, display) {
private var content: ComposeView? = null
init {
setCancelable(false)
setCanceledOnTouchOutside(false)
setOnDismissListener { DualScreenPanel.detach(this) }
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
applyImmersiveMode()
val decor = window?.decorView ?: return
decor.setViewTreeLifecycleOwner(host)
decor.setViewTreeViewModelStoreOwner(host)
decor.setViewTreeSavedStateRegistryOwner(host)
decor.setViewTreeOnBackPressedDispatcherOwner(host)
val view = ComposeView(context)
content = view
view.setContent {
val model = DualScreenPanel.model
val request = DualScreenPanel.typing
val typingOn = request != null && DualScreenPanel.typingShown
LaunchedEffect(typingOn) { acceptFocus(typingOn) }
DroidDeckTheme(model?.theme, appScale = model?.appScale ?: AppUiPrefs.DEFAULT_SCALE) {
Box(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.background)) {
if (request != null && typingOn) TypingPanel(request) {
if (DualScreenPanel.typing === request) DualScreenPanel.finishTyping()
} else if (model != null) DualPanelContent(model)
}
}
}
setContentView(view)
}
private fun acceptFocus(on: Boolean) {
val window = window ?: return
if (on) {
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
content?.requestFocus()
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
host.window?.decorView?.requestFocus()
}
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) applyImmersiveMode()
}
@Suppress("OVERRIDE_DEPRECATION")
override fun onBackPressed() {
if (DualScreenPanel.typingShown) DualScreenPanel.finishTyping()
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (DualScreenPanel.typingShown && event.keyCode == KeyEvent.KEYCODE_BUTTON_B) {
if (event.action == KeyEvent.ACTION_UP && !event.isCanceled) DualScreenPanel.finishTyping()
return true
}
return super.dispatchKeyEvent(event)
}
private fun applyImmersiveMode() {
@Suppress("DEPRECATION")
window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
}
}