mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
fix: "DroidDeck isn't responding" on dual-screen handhelds after the bottom screen sits idle (#1917)
The bottom-screen panel handed focus back to the main screen only when it opened or was touched within the last second. When the panel became the active screen later, the paused launcher kept no focused window, so controller input waited until Android reported the app as not responding. The panel now hands focus back whenever it becomes the active screen or gains window focus, unless bottom-screen typing is open or an app the launcher opened is in front.
This commit is contained in:
1 parent
0a07926ef3
commit
bfa61b5139
2 files changed
+4
-23
No files matched your search
@@ -166,18 +166,13 @@ object DualScreenPanel {
|
||||
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) {
|
||||
val task = focusTask(false) ?: return
|
||||
val task = focusTask(true) ?: return
|
||||
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager
|
||||
runCatching {
|
||||
manager.appTasks.firstOrNull {
|
||||
@@ -245,21 +240,16 @@ class DualScreenActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private var topResumed = false
|
||||
private var fresh = true
|
||||
private var touchedAt = Long.MIN_VALUE
|
||||
|
||||
override fun onTopResumedActivityChanged(isTopResumedActivity: Boolean) {
|
||||
super.onTopResumedActivityChanged(isTopResumedActivity)
|
||||
topResumed = isTopResumedActivity
|
||||
val took = DualScreenPanel.tookFocus(fresh, touchedAt, android.os.SystemClock.uptimeMillis())
|
||||
fresh = false
|
||||
if (isTopResumedActivity && !DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this, fromPanel = took)
|
||||
if (isTopResumedActivity && !DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this, fromPanel = true)
|
||||
}
|
||||
|
||||
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)
|
||||
if (event.actionMasked == android.view.MotionEvent.ACTION_DOWN && topResumed && !DualScreenPanel.typingShown) {
|
||||
DualScreenPanel.returnFocus(this, fromPanel = true)
|
||||
}
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user