mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix: "DroidDeck isn't responding" on dual-screen handhelds after the bottom screen takes focus (#1871)
This commit is contained in:
1 parent
6673a892e2
commit
8088e47d14
4 files changed
+98
-11
No files matched your search
@@ -1576,7 +1576,10 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) applyLauncherFullscreen()
|
||||
if (hasFocus) {
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
applyLauncherFullscreen()
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyLauncherFullscreen() {
|
||||
@@ -1635,7 +1638,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
|
||||
override fun onPause() {
|
||||
compatLaunchVisible = false
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29) com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, true)
|
||||
if (android.os.Build.VERSION.SDK_INT >= 29) com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, true)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
@@ -1643,6 +1646,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
super.onResume()
|
||||
compatLaunchVisible = true
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(taskId, false)
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.ownerPaused(taskId, false)
|
||||
orientation = SessionPrefs.orientation(this)
|
||||
launcherOrientation = com.droiddeck.launcher.core.AppUiPrefs.orientation(this)
|
||||
requestedOrientation = launcherOrientation
|
||||
|
||||
@@ -148,7 +148,15 @@ object HomeApp {
|
||||
}.getOrNull()
|
||||
|
||||
fun startShortcut(context: Context, info: ShortcutInfo) {
|
||||
context.getSystemService(LauncherApps::class.java).startShortcut(info, null, null)
|
||||
val task = generateSequence(context) { (it as? android.content.ContextWrapper)?.baseContext }
|
||||
.filterIsInstance<android.app.Activity>().firstOrNull()?.taskId
|
||||
task?.let { com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(it, true) }
|
||||
try {
|
||||
context.getSystemService(LauncherApps::class.java).startShortcut(info, null, null)
|
||||
} catch (e: Exception) {
|
||||
task?.let { com.droiddeck.launcher.ui.DualScreenPanel.yieldTo(it, false) }
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
fun openAppInfo(context: Context, app: LaunchableApp) {
|
||||
|
||||
@@ -70,6 +70,7 @@ object DualScreenPanel {
|
||||
set(value) { field = value; available = value || activity != null }
|
||||
private var ownerTask = -1
|
||||
private var ownerYielded = false
|
||||
private var ownerPaused = false
|
||||
|
||||
var typing by mutableStateOf<TypingRequest?>(null)
|
||||
private set
|
||||
@@ -120,6 +121,7 @@ object DualScreenPanel {
|
||||
displayId = display
|
||||
ownerTask = task
|
||||
ownerYielded = false
|
||||
ownerPaused = false
|
||||
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)
|
||||
@@ -153,15 +155,27 @@ object DualScreenPanel {
|
||||
if (ownerTask == task) ownerYielded = app
|
||||
}
|
||||
|
||||
internal fun returnFocus(context: Context) {
|
||||
if (ownerYielded) return
|
||||
val task = ownerTask.takeIf { it >= 0 } ?: return
|
||||
fun ownerPaused(task: Int, paused: Boolean) {
|
||||
if (ownerTask == task) ownerPaused = paused
|
||||
}
|
||||
|
||||
internal fun focusTask(fromPanel: Boolean): Int? {
|
||||
if (ownerYielded || (ownerPaused && !fromPanel)) return null
|
||||
return ownerTask.takeIf { it >= 0 }
|
||||
}
|
||||
|
||||
internal fun tookFocus(fresh: Boolean, touchedAt: Long, now: Long): Boolean =
|
||||
fresh || now - touchedAt in 0..TOUCH_FOCUS_MS
|
||||
|
||||
private const val TOUCH_FOCUS_MS = 1000L
|
||||
|
||||
internal fun returnFocus(context: Context, fromPanel: Boolean = false) {
|
||||
val task = focusTask(fromPanel) ?: return
|
||||
runCatching { (context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager).moveTaskToFront(task, 0) }
|
||||
}
|
||||
|
||||
internal fun reclaimFocus(context: Context) {
|
||||
if (ownerYielded) return
|
||||
val task = ownerTask.takeIf { it >= 0 } ?: return
|
||||
val task = focusTask(false) ?: return
|
||||
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager
|
||||
runCatching {
|
||||
manager.appTasks.firstOrNull {
|
||||
@@ -209,10 +223,10 @@ class DualScreenActivity : ComponentActivity() {
|
||||
runCatching { (getSystemService(ACTIVITY_SERVICE) as android.app.ActivityManager).moveTaskToFront(taskId, 0) }
|
||||
} else {
|
||||
unfocusPending = true
|
||||
DualScreenPanel.returnFocus(this)
|
||||
DualScreenPanel.returnFocus(this, fromPanel = true)
|
||||
window.decorView.postDelayed({
|
||||
if (!unfocusPending || DualScreenPanel.typingShown) return@postDelayed
|
||||
if (window.decorView.hasWindowFocus()) DualScreenPanel.returnFocus(this) else dropFocus()
|
||||
if (window.decorView.hasWindowFocus()) DualScreenPanel.returnFocus(this, fromPanel = true) else dropFocus()
|
||||
}, 400)
|
||||
}
|
||||
}
|
||||
@@ -228,9 +242,24 @@ class DualScreenActivity : ComponentActivity() {
|
||||
if (!DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this)
|
||||
}
|
||||
|
||||
private var topResumed = false
|
||||
private var fresh = true
|
||||
private var touchedAt = Long.MIN_VALUE
|
||||
|
||||
override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
|
||||
super.onTopResumedActivityChanged(isTopResumedActivity)
|
||||
if (isTopResumedActivity && !DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this)
|
||||
topResumed = isTopResumedActivity
|
||||
val took = DualScreenPanel.tookFocus(fresh, touchedAt, android.os.SystemClock.uptimeMillis())
|
||||
fresh = false
|
||||
if (isTopResumedActivity && !DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this, fromPanel = took)
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: android.view.MotionEvent): Boolean {
|
||||
if (event.actionMasked == android.view.MotionEvent.ACTION_DOWN) {
|
||||
touchedAt = event.downTime
|
||||
if (topResumed && !DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this, fromPanel = true)
|
||||
}
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
@@ -251,6 +280,7 @@ class DualScreenActivity : ComponentActivity() {
|
||||
if (event.action == KeyEvent.ACTION_UP && !event.isCanceled) DualScreenPanel.finishTyping()
|
||||
return true
|
||||
}
|
||||
if (topResumed && !DualScreenPanel.typingShown && event.action == KeyEvent.ACTION_DOWN) DualScreenPanel.returnFocus(this, fromPanel = true)
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user