diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index b9597649ed..219d691020 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -356,6 +356,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private var glassesOutputActive by mutableStateOf(false) private var pausedFrame by mutableStateOf(null) private var pausedFrameWanted = false + private var pauseAnimated by mutableStateOf(false) private var trackingRecovery by mutableStateOf(null) private var glasses3dForVr = false private var ended = false @@ -1106,6 +1107,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { pipSupported = com.droiddeck.launcher.session.SessionPipController.supported(this@SessionActivity), pipAutoEnter = pipAutoEnter, onPip = { pip.enter() }, + onPause = ::pauseNow, onPipAutoEnter = { on -> SessionPrefs.setPipAutoEnter(this@SessionActivity, on) pipAutoEnter = on @@ -1175,17 +1177,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { com.droiddeck.launcher.ui.AchievementNotificationOverlay() // Auto and Native resume on their own as the session comes back; only a failed resume needs the button. val autoResume = suspendPolicy == SessionPrefs.SUSPEND_AUTO || suspendPolicy == SessionPrefs.SUSPEND_NATIVE + LaunchedEffect(SessionState.manualPause, SessionState.suspended) { + if (!SessionState.manualPause && !SessionState.suspended) pauseAnimated = false + } SessionPausedOverlay( - suspended = SessionState.suspended && (!autoResume || SessionState.resumeFailed), + suspended = SessionState.suspended && (!autoResume || SessionState.resumeFailed || SessionState.manualPause), engaged = SessionState.resumeRequested || SessionState.resuming, failures = SessionState.resumeFailures, frame = pausedFrame, + animateIn = pauseAnimated, title = pausedTitle(), onResume = { SessionService.resume(this@SessionActivity) }, onFrameNeeded = ::requestPausedFrame, onHidden = { pausedFrame = null pausedFrameWanted = false + pauseAnimated = false }, ) if (leaving) com.droiddeck.launcher.ui.FloodSpread( @@ -3106,10 +3113,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } // The frozen game cannot draw again, so the paused overlay shows a copy taken while the surface still holds its frame. - private fun capturePausedFrame() { + private fun capturePausedFrame(manual: Boolean = false) { if (!SessionState.running || pipUi || isInPictureInPictureMode || glassesOutputActive) return if (SessionState.suspended && pausedFrame != null) return - if (suspendPolicy == SessionPrefs.SUSPEND_NEVER || !::surfaceView.isInitialized) return + if ((suspendPolicy == SessionPrefs.SUSPEND_NEVER && !manual) || !::surfaceView.isInitialized) return if (surfaceView.holder.surface?.isValid != true) return val width = surfaceView.width val height = surfaceView.height @@ -3141,6 +3148,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { } } + private fun pauseNow() { + if (!SessionState.running || SessionState.suspended) return + pauseAnimated = true + drawerOpen = false + pausedFrame = null + capturePausedFrame(manual = true) + SessionService.pause(this) + } + // Sessions that froze from picture-in-picture, or before onPause could copy a frame, have none; the // compositor shows the frozen frame again once its output is back, so copy it from there. private fun requestPausedFrame() { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 24e9ef553b..74785e34fc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -91,6 +91,7 @@ class SessionService : Service() { private var screenOn = true private var sessionDisplayId = Display.DEFAULT_DISPLAY private var manualPauseRequested = false + private var manualHold = false private var steamSleepToken: String? = null private var nativeSleepToken: String? = null private var nativeSleepReady = false @@ -274,7 +275,11 @@ class SessionService : Service() { val hold = intent?.getBooleanExtra(EXTRA_HOLD, false) == true if (hold == signInHold) return START_NOT_STICKY signInHold = hold - if (hold) manualPauseRequested = false + if (hold) { + manualPauseRequested = false + manualHold = false + SessionState.manualPause = false + } suspendAttemptFailed = false updateSuspendPolicy() return START_NOT_STICKY @@ -304,6 +309,14 @@ class SessionService : Service() { updateSuspendPolicy() return START_NOT_STICKY } + ACTION_PAUSE_NOW -> { + if (!SessionState.running || SessionState.suspended || signInHold) return START_NOT_STICKY + manualHold = true + SessionState.manualPause = true + suspendAttemptFailed = false + updateSuspendPolicy() + return START_NOT_STICKY + } ACTION_RESUME -> { resumeSession() return START_NOT_STICKY @@ -346,6 +359,8 @@ class SessionService : Service() { SessionState.resumeRequested = false SessionState.resuming = false SessionState.resumeFailed = false + manualHold = false + SessionState.manualPause = false SessionState.pipActive = false pipTask = false SessionState.program = intent?.getStringExtra(EXTRA_PROGRAM) @@ -1332,6 +1347,8 @@ class SessionService : Service() { if (panelVisible) activityVisible = true screenOn = readScreenOn() manualPauseRequested = false + manualHold = false + SessionState.manualPause = false suspendDownloadNow = false if (steamSleepToken == null && (nativeSleepToken == null || nativeSleepFallback || nativeSleepIdle)) requestSteamWake() completeNativeSleep() @@ -1540,11 +1557,11 @@ class SessionService : Service() { } val controller = suspendController ?: return if (downloadsBlockingSuspend) acquireLocks() - val steamPause = SessionState.mode == MODE_STEAM && !downloadsBlockingSuspend && when (suspendPolicy) { + val steamPause = SessionState.mode == MODE_STEAM && (manualHold || !downloadsBlockingSuspend && when (suspendPolicy) { SessionPrefs.SUSPEND_AUTO, SessionPrefs.SUSPEND_NATIVE -> hidden SessionPrefs.SUSPEND_MANUAL -> manualPauseRequested else -> false - } + }) if (!steamPause) { completeNativeSleep() } else if (nativeSleepToken == null && steamSleepToken == null && @@ -1552,7 +1569,7 @@ class SessionService : Service() { prepareNativeSleep() } val prepared = SessionState.mode != MODE_STEAM || nativeSleepReady - val shouldSuspend = steamSleepToken != null || when (suspendPolicy) { + val shouldSuspend = steamSleepToken != null || (manualHold && prepared) || when (suspendPolicy) { SessionPrefs.SUSPEND_AUTO -> hidden && prepared && !downloadsBlockingSuspend SessionPrefs.SUSPEND_NATIVE -> hidden && nativeSleepReady && !downloadsBlockingSuspend SessionPrefs.SUSPEND_MANUAL -> manualPauseRequested && prepared && !downloadsBlockingSuspend @@ -1600,6 +1617,8 @@ class SessionService : Service() { SessionEvents.record("session.suspend_cancelled") } else { suspendAttemptFailed = true + manualHold = false + SessionState.manualPause = false Log.w(TAG, "could not confirm that the session stopped") } } @@ -1648,7 +1667,7 @@ class SessionService : Service() { } private fun resumeSteamSleepOnReturn() { - if (suspendPolicy in setOf(SessionPrefs.SUSPEND_AUTO, SessionPrefs.SUSPEND_NATIVE) && hasVisibleSurface) { + if (!manualHold && suspendPolicy in setOf(SessionPrefs.SUSPEND_AUTO, SessionPrefs.SUSPEND_NATIVE) && hasVisibleSurface) { if (steamSleepToken == null && (nativeSleepToken == null || nativeSleepFallback || nativeSleepIdle)) requestSteamWake() completeNativeSleep() completeSteamSleep() @@ -1716,6 +1735,8 @@ class SessionService : Service() { SessionState.resumeRequested = false SessionState.resuming = false SessionState.resumeFailed = false + manualHold = false + SessionState.manualPause = false SessionState.pipActive = false pipTask = false SessionState.guestPid = -1 @@ -2068,6 +2089,7 @@ class SessionService : Service() { const val ACTION_STOP = "com.droiddeck.launcher.STOP_SESSION" const val ACTION_RESUME = "com.droiddeck.launcher.RESUME_SESSION" const val ACTION_SUSPEND_NOW = "com.droiddeck.launcher.SUSPEND_NOW" + private const val ACTION_PAUSE_NOW = "com.droiddeck.launcher.PAUSE_NOW" private const val ACTION_PIP_BEGIN = "com.droiddeck.launcher.PIP_BEGIN" const val ACTION_LAUNCH_GAME = "com.droiddeck.launcher.LAUNCH_STEAM_GAME" const val ACTION_HOME_GUIDE = "com.droiddeck.launcher.HOME_GUIDE" @@ -2187,6 +2209,10 @@ class SessionService : Service() { context.startService(Intent(context, SessionService::class.java).setAction(ACTION_SIGN_IN_HOLD).putExtra(EXTRA_HOLD, hold)) } + fun pause(context: Context) { + context.startService(Intent(context, SessionService::class.java).setAction(ACTION_PAUSE_NOW)) + } + fun resume(context: Context) { if (!SessionState.running) return if (SessionState.suspended) SessionState.resumeRequested = true diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt index 52544f2fc0..5f3ae0154a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt @@ -53,6 +53,7 @@ object SessionState { var resuming by mutableStateOf(false) var resumeFailures by mutableIntStateOf(0) var resumeFailed by mutableStateOf(false) + var manualPause by mutableStateOf(false) @Volatile var pipActive = false @Volatile var program: String? = null diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index d9a50a20d3..70bc1d1a2e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -38,6 +38,7 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.material.icons.outlined.DesktopWindows import androidx.compose.material.icons.outlined.Layers import androidx.compose.material.icons.outlined.ScreenShare +import androidx.compose.material.icons.outlined.Pause import androidx.compose.material.icons.outlined.PictureInPictureAlt import androidx.compose.material.icons.automirrored.outlined.ExitToApp import androidx.compose.material.icons.outlined.Settings @@ -285,6 +286,7 @@ class DrawerActions( val pipSupported: Boolean = false, val pipAutoEnter: Boolean = false, val onPip: () -> Unit = {}, + val onPause: () -> Unit = {}, val onPipAutoEnter: (Boolean) -> Unit = {}, val unfoldedControls: Boolean? = null, val onUnfoldedControls: (Boolean) -> Unit = {}, @@ -427,17 +429,15 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont } .padding(12.dp), ) { - val title = a.title ?: if (a.steam) stringResource(R.string.drawer_steam) else stringResource(R.string.drawer_desktop) - if (narrow) Text(title, fontSize = 18.sp, fontWeight = FontWeight.Bold, - color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, - modifier = Modifier.fillMaxWidth().padding(bottom = 6.dp)) Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().heightIn(min = 44.dp), ) { - if (narrow) Spacer(Modifier.weight(1f)) else Text(title, fontSize = 18.sp, fontWeight = FontWeight.Bold, - color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + Spacer(Modifier.weight(1f)) + SteamActionPill( + stringResource(R.string.stores_dl_pause), Icons.Outlined.Pause, focus.track(page, "pause"), + ) { host.open = null; a.onPause() } if (a.pipSupported) SteamActionPill( stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"), ) { host.open = null; a.onPip() } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionPausedOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionPausedOverlay.kt index afe9f0ba4c..8f7be4e226 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionPausedOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionPausedOverlay.kt @@ -77,6 +77,7 @@ class PausedFrame(val image: ImageBitmap, val bounds: android.graphics.Rect) private const val CARD_SCALE = 0.82f private const val FRAME_WAIT_MS = 600L +private val PopEasing = CubicBezierEasing(0.3f, 1.5f, 0.4f, 1f) private fun tone(saturation: Float, brightness: Float): ColorMatrix = ColorMatrix().apply { @@ -90,6 +91,7 @@ fun SessionPausedOverlay( engaged: Boolean, failures: Int, frame: PausedFrame?, + animateIn: Boolean, title: String, onResume: () -> Unit, onFrameNeeded: () -> Unit, @@ -106,6 +108,14 @@ fun SessionPausedOverlay( LaunchedEffect(suspended, engaged) { when { suspended && !engaged -> { + if (!shown && animateIn) { + shown = true + launch { press.animateTo(1f, Motion.sp(0.5f, Spring.StiffnessMedium)) } + launch { ring.animateTo(0f, Motion.tw(200)) } + launch { lift.animateTo(1f, Motion.tw(520)) } + orb.animateTo(1f, Motion.tw(380, delay = if (orb.value < 0.5f) 260 else 0, easing = PopEasing)) + return@LaunchedEffect + } if (!shown) { if (currentFrame == null) { onFrameNeeded()