mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Use the second screen on dual-screen handhelds (#1734)
* Use the second screen on dual-screen handhelds Detect built-in second screens such as the Retroid Pocket Duo and AYN Thor. The sections move to a menu on the bottom screen, L2 and R2 switch sections, and text fields type on the bottom screen so the top keeps the full view. Sessions open the bottom-screen trackpad and keyboard when they start. Setup gains a Dual screen choice (Automatic, On, Off) with toggles for the bottom menu and the in-game controls. Closing the bottom menu no longer ends a running session. * Type into Steam from the bottom screen While the bottom-screen trackpad and keyboard controls are open in a Steam session, Steam's own on-screen keyboard no longer covers the top screen. The agent keeps Steam's text target and asks the app instead, which opens the Android keyboard on the bottom screen and hands focus back to the game when it closes. Modal and VR keyboards, and sessions without the bottom controls, keep Steam's keyboard. The Show keyboard button now follows the keyboard when it is closed another way. * Open the bottom controls after the first frame and tidy dual-screen translations * Move the in-game menu to the bottom screen on dual-screen handhelds Fix controller input and focus on the second screen: keys and sticks reach the game after touching the bottom controls, closing the bottom controls returns focus to the game, B closes bottom typing, and the typing panel keeps a focusable window until focus has left it. * Let B close the open layer of the session menu first and focus the selected bottom-screen mode * Let the Retroid Pocket Duo Home double press open its quick menu during sessions * Open the keyboard on the bottom screen for Steam text fields and hide it on Enter or when the field loses focus * Keep controller focus on the top screen when a section is picked on the bottom screen * Keep LB and RB on the store tabs and let Back return from a store to its tab * Show the Adreno 722 as supported on the Retroid Pocket Duo * Label the Steam integration suggestion's close button Close and cover that closing it is permanent * Close the docked menu with its presentation, keep a focus picked during the stop delay, and ignore panel picks on process-settings pages
This commit is contained in:
1 parent
e9e0186e66
commit
283e3b4549
65 files changed
+2425
-350
No files matched your search
@@ -525,6 +525,12 @@ class FrontEndActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
private var secondScreenDisplays by mutableStateOf<List<SecondScreenDisplay>>(emptyList())
|
||||
private var dualDisplayId by mutableStateOf(-1)
|
||||
private var dualScreenDevice by mutableStateOf(false)
|
||||
private var dualScreenMode by mutableStateOf(com.droiddeck.launcher.input.DualScreen.MODE_AUTO)
|
||||
private var dualScreenLauncher by mutableStateOf(true)
|
||||
private var dualScreenControls by mutableStateOf(true)
|
||||
private var launcherStarted = false
|
||||
private lateinit var displayManager: DisplayManager
|
||||
private val secondScreenDisplayListener = object : DisplayManager.DisplayListener {
|
||||
override fun onDisplayAdded(displayId: Int) = refreshSecondScreenDisplays()
|
||||
@@ -1017,6 +1023,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
integrationFocus = integrationFocus,
|
||||
androidApps = androidApps,
|
||||
secondScreenDisplays = secondScreenDisplays,
|
||||
dualScreen = dualDisplayId >= 0 && com.droiddeck.launcher.ui.DualScreenPanel.available,
|
||||
dualScreenDevice = dualScreenDevice,
|
||||
dualScreenMode = dualScreenMode,
|
||||
dualScreenLauncher = dualScreenLauncher,
|
||||
dualScreenControls = dualScreenControls,
|
||||
packages = packageRows,
|
||||
packageCatalogLoading = catalogLoading,
|
||||
packageBusyId = pkgId,
|
||||
@@ -1245,6 +1256,18 @@ class FrontEndActivity : ComponentActivity() {
|
||||
onStoresSort = { sort -> SessionPrefs.setStoresSort(this, sort); storesSort = sort },
|
||||
onStoresView = { view -> SessionPrefs.setStoresView(this, view); storesView = view },
|
||||
onLibraryChanged = { refreshAddedGames(); refresh() },
|
||||
onDualScreenMode = { mode ->
|
||||
SessionPrefs.setDualScreenMode(this, mode)
|
||||
refreshSecondScreenDisplays()
|
||||
},
|
||||
onDualScreenLauncher = { on ->
|
||||
SessionPrefs.setDualScreenLauncher(this, on)
|
||||
refreshSecondScreenDisplays()
|
||||
},
|
||||
onDualScreenControls = { on ->
|
||||
SessionPrefs.setDualScreenSessionControls(this, on)
|
||||
dualScreenControls = on
|
||||
},
|
||||
onAnimationsEnabled = { on ->
|
||||
SessionPrefs.setAnimationsEnabled(this, on)
|
||||
animationsEnabled = on
|
||||
@@ -1621,6 +1644,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
addDataScheme("file")
|
||||
})
|
||||
displayManager.registerDisplayListener(secondScreenDisplayListener, ui)
|
||||
launcherStarted = true
|
||||
refreshSecondScreenDisplays()
|
||||
getSystemService(android.content.pm.LauncherApps::class.java).registerCallback(packageCallback, ui)
|
||||
HomeWidgets.startListening(this)
|
||||
@@ -1663,6 +1687,8 @@ class FrontEndActivity : ComponentActivity() {
|
||||
com.droiddeck.launcher.stores.StoresState.libraryListener = null
|
||||
com.droiddeck.launcher.stores.battlenet.BattleNetClient.opener = null
|
||||
displayManager.unregisterDisplayListener(secondScreenDisplayListener)
|
||||
launcherStarted = false
|
||||
com.droiddeck.launcher.ui.DualScreenPanel.hide()
|
||||
flood = null
|
||||
returning = null
|
||||
floodProgress = 0f
|
||||
@@ -1696,7 +1722,20 @@ class FrontEndActivity : ComponentActivity() {
|
||||
if (!::displayManager.isInitialized) return
|
||||
// The launcher can itself be shown on a non-default display (DeX, an external monitor); that one is not a "second screen".
|
||||
val ownDisplayId = if (android.os.Build.VERSION.SDK_INT >= 30) display?.displayId ?: android.view.Display.DEFAULT_DISPLAY else @Suppress("DEPRECATION") windowManager.defaultDisplay.displayId
|
||||
secondScreenDisplays = SecondScreenDisplays.available(displayManager, ownDisplayId)
|
||||
dualScreenMode = SessionPrefs.dualScreenMode(this)
|
||||
secondScreenDisplays = if (dualScreenMode == com.droiddeck.launcher.input.DualScreen.MODE_OFF) emptyList()
|
||||
else SecondScreenDisplays.available(displayManager, ownDisplayId)
|
||||
dualScreenDevice = com.droiddeck.launcher.input.DualScreen.anyDisplay(displayManager, ownDisplayId) != null
|
||||
dualScreenLauncher = SessionPrefs.dualScreenLauncher(this)
|
||||
dualScreenControls = SessionPrefs.dualScreenSessionControls(this)
|
||||
val target = com.droiddeck.launcher.input.DualScreen.display(this, displayManager, ownDisplayId)
|
||||
dualDisplayId = if (dualScreenLauncher) target?.displayId ?: -1 else -1
|
||||
syncDualPanel()
|
||||
}
|
||||
|
||||
private fun syncDualPanel() {
|
||||
if (launcherStarted && dualDisplayId >= 0) com.droiddeck.launcher.ui.DualScreenPanel.show(this, dualDisplayId, taskId)
|
||||
else com.droiddeck.launcher.ui.DualScreenPanel.hide()
|
||||
}
|
||||
|
||||
private fun launchAndroidApp(app: HomeApp.LaunchableApp, displayId: Int?) {
|
||||
|
||||
@@ -294,7 +294,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private val resumeKeysDown = mutableSetOf<Pair<Int, Int>>()
|
||||
private val drawerShortcutKeysDown = mutableSetOf<Pair<Int, Int>>()
|
||||
|
||||
private var drawerOpen by mutableStateOf(false)
|
||||
private var drawerOpenState by mutableStateOf(false)
|
||||
private var typingReturnMode: SecondScreenMode? = null
|
||||
private var drawerDocked by mutableStateOf(false)
|
||||
private var drawerLayerOpen = false
|
||||
private var drawerBackRequests by mutableIntStateOf(0)
|
||||
private var drawerOpen: Boolean
|
||||
get() = drawerOpenState
|
||||
set(value) {
|
||||
if (value == drawerOpenState) return
|
||||
drawerLayerOpen = false
|
||||
if (value) drawerDocked = dockDrawer() && openDockedMenu()
|
||||
drawerOpenState = value
|
||||
if (!value && drawerDocked) closeDockedMenu()
|
||||
}
|
||||
private var quitFrom by mutableStateOf<androidx.compose.ui.geometry.Rect?>(null)
|
||||
private var quitFlooded = false
|
||||
private var leaving by mutableStateOf(false)
|
||||
@@ -732,6 +745,20 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
androidx.compose.runtime.LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, pipUi) { updatePointerCapture() }
|
||||
androidx.compose.runtime.LaunchedEffect(pipUi) { hud.setHidden(pipUi) }
|
||||
androidx.compose.runtime.LaunchedEffect(AgentGuest.steamKeyboard) { updateOnScreenControls() }
|
||||
val keyboardRequestsSeen = androidx.compose.runtime.remember { intArrayOf(AgentGuest.keyboardRequests) }
|
||||
androidx.compose.runtime.LaunchedEffect(AgentGuest.keyboardRequests) {
|
||||
if (AgentGuest.keyboardRequests != keyboardRequestsSeen[0]) {
|
||||
keyboardRequestsSeen[0] = AgentGuest.keyboardRequests
|
||||
openBottomKeyboard()
|
||||
}
|
||||
}
|
||||
val keyboardDismissalsSeen = androidx.compose.runtime.remember { intArrayOf(AgentGuest.keyboardDismissals) }
|
||||
androidx.compose.runtime.LaunchedEffect(AgentGuest.keyboardDismissals) {
|
||||
if (AgentGuest.keyboardDismissals != keyboardDismissalsSeen[0]) {
|
||||
keyboardDismissalsSeen[0] = AgentGuest.keyboardDismissals
|
||||
secondScreenPresentation?.closeFieldKeyboard()
|
||||
}
|
||||
}
|
||||
androidx.compose.runtime.LaunchedEffect(picturePosition, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() }
|
||||
DroidDeckTheme {
|
||||
if (pipUi) {
|
||||
@@ -896,8 +923,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
syncLossless()
|
||||
releasePads()
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
val requested = sessionOverlay.requestFocus()
|
||||
Log.i(TAG, "drawer root focus requested=$requested focused=${sessionOverlay.hasFocus()}")
|
||||
val requested = focusDrawer()
|
||||
Log.i(TAG, "drawer root focus requested=$requested docked=$drawerDocked")
|
||||
} else {
|
||||
releaseDrawerDirection()
|
||||
}
|
||||
@@ -935,236 +962,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
onAndroidKeyboard = { pcKeyboardOpen = false; keyboard?.toggle() },
|
||||
onClose = { pcKeyboardOpen = false },
|
||||
)
|
||||
SessionDrawer(drawerOpen, drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, a = DrawerActions(
|
||||
steam = SessionState.mode == SessionService.MODE_STEAM,
|
||||
direct = noSteamSession(),
|
||||
title = if (SessionState.mode == SessionService.MODE_RUN)
|
||||
com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_title_game) else null,
|
||||
isHomeApp = isHomeApp,
|
||||
androidApps = androidApps,
|
||||
hudOn = hudOn,
|
||||
hudConfig = hudConfig,
|
||||
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
|
||||
effects = effects,
|
||||
cardboard = cardboard,
|
||||
cardboardSensor = hasRotationSensor,
|
||||
onCardboard = { c -> SessionPrefs.setCardboard(this@SessionActivity, c); applyCardboard(c) },
|
||||
onCardboardRecenter = { headTracker?.recenter() },
|
||||
glassesPresent = glasses.present,
|
||||
glassesOutput = glassesOutputActive,
|
||||
onGlassesRecenter = {
|
||||
headTracker?.recenter()
|
||||
com.droiddeck.launcher.glasses.GlassesMenuMirror.recenter()
|
||||
},
|
||||
steamVr = steamVrStatus,
|
||||
immersiveSteamVr = com.droiddeck.launcher.session.QuestExperimental.isSupported(),
|
||||
onSteamVr = { action -> steamVrAction(action) },
|
||||
textureAnisotropy = if (drawerGameProfileId == null) textureAnisotropy else drawerTextureAnisotropy,
|
||||
textureLodBias = if (drawerGameProfileId == null) textureLodBias else drawerTextureLodBias,
|
||||
frameGen = frameGen,
|
||||
lossless = lossless,
|
||||
oscMode = oscMode, onScreenButtonsVisible = onScreenButtonsVisible, suspendPolicy = suspendPolicy,
|
||||
steamDownloadsInBackground = steamDownloadsInBackground, touchMode = touchMode,
|
||||
micAvailable = SessionState.micAvailable && !SessionState.suspended,
|
||||
micEnabled = SessionState.micEnabled,
|
||||
onMicEnabled = { SessionService.setMicEnabled(this@SessionActivity, it) },
|
||||
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
|
||||
fexPreset = fexPreset,
|
||||
secondScreenMode = secondScreenMode,
|
||||
secondScreenDisplays = secondScreenDisplays,
|
||||
selectedSecondScreenDisplay = selectedSecondScreenDisplay,
|
||||
onHud = { on -> SessionPrefs.setHudEnabled(this@SessionActivity, on); hudOn = on; hud.refresh() },
|
||||
onHudSetting = { key, value -> hudConfig = FusionHudConfig.set(this@SessionActivity, key, value); hud.applyConfig() },
|
||||
onHudReset = { hudConfig = FusionHudConfig.reset(this@SessionActivity); hud.applyConfig() },
|
||||
onHudExport = { exportHudDiagnostics() },
|
||||
onUpscaler = { m ->
|
||||
SessionPrefs.setUpscaler(this@SessionActivity, m); upscaler = m
|
||||
WaylandCompositor.nativeSetUpscaler(m)
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(effects, m)?.name)
|
||||
},
|
||||
onUpscaleSharpness = { pct ->
|
||||
SessionPrefs.setUpscaleSharpness(this@SessionActivity, pct); upscaleSharpness = pct
|
||||
WaylandCompositor.nativeSetUpscaleSharpness(pct)
|
||||
},
|
||||
onEffects = { e ->
|
||||
SessionPrefs.setScreenEffects(this@SessionActivity, e); effects = e
|
||||
e.push(upscaler)
|
||||
},
|
||||
onTextureAnisotropy = { value ->
|
||||
drawerGameProfileId?.let { appId ->
|
||||
SessionPrefs.setGameTextureAnisotropy(this@SessionActivity, appId.toString(), value)
|
||||
drawerTextureAnisotropy = value
|
||||
} ?: value?.let {
|
||||
SessionPrefs.setTextureAnisotropy(this@SessionActivity, it)
|
||||
textureAnisotropy = it
|
||||
}
|
||||
},
|
||||
onTextureLodBias = { value ->
|
||||
drawerGameProfileId?.let { appId ->
|
||||
SessionPrefs.setGameTextureLodBias(this@SessionActivity, appId.toString(), value)
|
||||
drawerTextureLodBias = value
|
||||
} ?: value?.let {
|
||||
SessionPrefs.setTextureLodBias(this@SessionActivity, it)
|
||||
textureLodBias = it
|
||||
}
|
||||
},
|
||||
onFrameGenPick = { mode ->
|
||||
FrameGen.set(this@SessionActivity, mode)
|
||||
readPrefs()
|
||||
applyFrameGen()
|
||||
},
|
||||
onImportLossless = {
|
||||
pickLossless.launch(InAppFilePicker.buildIntent(
|
||||
this@SessionActivity, listOf("dll"), getString(R.string.lsfg_pick_title)))
|
||||
},
|
||||
onKeyboard = { drawerOpen = false; pcKeyboardOpen = false; keyboard?.toggle() },
|
||||
onHardwareKeyboard = ::togglePcKeyboard,
|
||||
controller = controllerSettings,
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamButton = { on -> updateControllerPrefs { ControllerPrefs.setSteamButton(this@SessionActivity, on) } },
|
||||
onQamButton = { on -> updateControllerPrefs { ControllerPrefs.setQamButton(this@SessionActivity, on) } },
|
||||
onKeyboardButton = { on -> updateControllerPrefs { ControllerPrefs.setKeyboardButton(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
onAchievements = achievementsInFront?.let { { drawerOpen = false; achievementsOpen = true } },
|
||||
achievementsProgress = achievementsInFront?.progress,
|
||||
padType = if (SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad) padType else null,
|
||||
onPadType = { id ->
|
||||
SessionPrefs.setSteamController(this@SessionActivity, id)
|
||||
com.droiddeck.launcher.session.SteamDeckPad.showPad(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setPadType(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.session.InputSysfsComponent.padTypeChanged(SessionPrefs.padType(id))
|
||||
padType = id
|
||||
},
|
||||
backActionsInverted = backActionsInverted,
|
||||
backDoubleTapMs = backDoubleTapMs,
|
||||
onBackDoubleTapMs = { ms ->
|
||||
SessionPrefs.setBackDoubleTapMs(this@SessionActivity, ms)
|
||||
backDoubleTapMs = ms
|
||||
},
|
||||
onBackActionsInverted = { inverted ->
|
||||
SessionPrefs.setBackActionsInverted(this@SessionActivity, inverted)
|
||||
backActionsInverted = inverted
|
||||
},
|
||||
lowLatency = lowLatency,
|
||||
onLowLatency = { on ->
|
||||
SessionPrefs.setLowLatency(this@SessionActivity, on)
|
||||
lowLatency = on
|
||||
applyLowLatency()
|
||||
},
|
||||
onOsc = { v ->
|
||||
SessionPrefs.setOscMode(this@SessionActivity, v)
|
||||
readPrefs()
|
||||
updateOnScreenControls()
|
||||
if (v == SessionPrefs.OSC_STEAM_TOUCH && com.droiddeck.launcher.input.SteamTouchDevice.current == null)
|
||||
Toast.makeText(this@SessionActivity, R.string.osc_style_next_session, Toast.LENGTH_LONG).show()
|
||||
},
|
||||
onEditSteamTouch = if (steamTouchAvailable && oscMode == SessionPrefs.OSC_STEAM_TOUCH && onScreenButtonsVisible) ({
|
||||
drawerOpen = false
|
||||
steamTouchControls?.startEditing()
|
||||
}) else null,
|
||||
onSuspendPolicy = { policy ->
|
||||
SessionPrefs.setSuspendPolicy(this@SessionActivity, SessionState.mode, policy)
|
||||
suspendPolicy = policy
|
||||
SessionService.suspendPolicyChanged(this@SessionActivity)
|
||||
},
|
||||
onSteamDownloadsInBackground = { enabled ->
|
||||
SessionPrefs.setSteamDownloadsInBackground(this@SessionActivity, enabled)
|
||||
steamDownloadsInBackground = enabled
|
||||
SessionService.suspendPolicyChanged(this@SessionActivity)
|
||||
},
|
||||
onTouch = { v -> SessionPrefs.setTouchMode(this@SessionActivity, v); readPrefs() },
|
||||
onGestureSettings = { drawerOpen = false; gestureSettingsOpen = true },
|
||||
onScreenKeys = { drawerOpen = false; screenKeys?.startEditing() },
|
||||
screenKeysShown = screenKeysShown,
|
||||
onScreenKeysShown = { shown ->
|
||||
screenKeysShown = shown
|
||||
com.droiddeck.launcher.input.ControllerPrefs.setScreenKeysShown(this@SessionActivity, shown)
|
||||
screenKeys?.stopEditing()
|
||||
screenKeys?.visibility = if (shown) View.VISIBLE else View.GONE
|
||||
},
|
||||
onScreenLayouts = {
|
||||
drawerOpen = false
|
||||
screenLayoutNames = layoutNames()
|
||||
screenLayoutsOpen = true
|
||||
},
|
||||
onFexPreset = { v -> SessionPrefs.setFexPreset(this@SessionActivity, v); readPrefs() },
|
||||
onSecondScreenMode = ::selectSecondScreenMode,
|
||||
onSecondScreenDisplay = ::selectSecondScreenDisplay,
|
||||
onLaunchAndroidApp = { app, displayId ->
|
||||
drawerOpen = false
|
||||
try {
|
||||
HomeApp.launch(this@SessionActivity, app, displayId)
|
||||
} catch (_: Exception) {
|
||||
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)
|
||||
}
|
||||
Toast.makeText(this@SessionActivity, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
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
|
||||
pip.refresh(true)
|
||||
},
|
||||
unfoldedControls = unfoldedControls,
|
||||
onUnfoldedControls = ::chooseUnfoldedControls,
|
||||
unfoldedControlsWithController = unfoldedControlsWithController,
|
||||
onUnfoldedControlsWithController = ::chooseUnfoldedControlsWithController,
|
||||
onBackground = { drawerOpen = false; pip.background(); moveTaskToBack(true) },
|
||||
onShareLogs = { drawerOpen = false; shareCurrentSessionLogs() },
|
||||
onStop = { drawerOpen = false; SessionService.stop(this@SessionActivity); finish() },
|
||||
onStopFrom = { onScreen ->
|
||||
drawerOpen = false
|
||||
if (onScreen == null || com.droiddeck.launcher.ui.Motion.scale == 0f || quitFrom != null) {
|
||||
if (quitFrom == null) { SessionService.stop(this@SessionActivity); finish() }
|
||||
} else {
|
||||
val at = IntArray(2).also { sessionOverlay.getLocationOnScreen(it) }
|
||||
quitFrom = onScreen.translate(-at[0].toFloat(), -at[1].toFloat())
|
||||
}
|
||||
},
|
||||
onClose = { drawerOpen = false },
|
||||
components = drawerComponents,
|
||||
onComponentsRefresh = {
|
||||
refreshDrawerComponents()
|
||||
drawerComponentMenu.refreshComponentCatalog(force = false)
|
||||
},
|
||||
componentCatalog = drawerComponentMenu.compCatalog,
|
||||
componentCatalogAt = drawerComponentMenu.compCatalogAt,
|
||||
componentCatalogChecking = drawerComponentMenu.compChecking,
|
||||
componentDownloads = drawerComponentMenu.compDownloads,
|
||||
componentDownloadRevision = drawerComponentMenu.compDownloadRevision,
|
||||
onComponentCatalogRefresh = { drawerComponentMenu.refreshComponentCatalog() },
|
||||
onComponentDownload = drawerComponentMenu::downloadComponent,
|
||||
gameProfiles = drawerGameProfileRefresh.data?.profiles.orEmpty(),
|
||||
selectedGameProfileId = drawerGameProfileId,
|
||||
selectedGameProfile = drawerGameProfileRefresh.data
|
||||
?.takeIf { it.selectedAppId == drawerGameProfileId }?.profile,
|
||||
gameProfilesLoaded = drawerGameProfileRefresh.loaded,
|
||||
gameProfileRefreshFailed = drawerGameProfileRefresh.failed,
|
||||
onSelectedGameProfile = ::selectDrawerGameProfile,
|
||||
onGameProfilesPageOpened = {
|
||||
drawerGameProfileFollowState.resumeFollowingSteam()
|
||||
drawerGameInventoryRevision++
|
||||
},
|
||||
onSelectedGameProfileRefresh = ::refreshDrawerGameProfile,
|
||||
gameFexPresetSaving = drawerGameFexPresetSaving,
|
||||
onGameFexPreset = ::setDrawerGameFexPreset,
|
||||
gameNoSteamSaving = drawerGameNoSteamSaving,
|
||||
onGameNoSteam = ::setDrawerGameNoSteam,
|
||||
onComponentSwap = { pid, comp, value -> swapDrawerComponent(pid, comp, value) },
|
||||
onGameComponent = ::setDrawerGameComponent,
|
||||
defaultProtonId = drawerDefaultProton,
|
||||
onDefaultProton = ::chooseDrawerDefaultProton,
|
||||
onGameProton = ::setDrawerGameProton,
|
||||
))
|
||||
if (!drawerDocked) SessionMenu(docked = false)
|
||||
LaunchedEffect(achievementsOpen) {
|
||||
if (achievementsOpen) {
|
||||
releasePads()
|
||||
@@ -1214,6 +1012,241 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
private fun SessionMenu(docked: Boolean) {
|
||||
SessionDrawer(drawerOpen, drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, docked = docked,
|
||||
backRequest = drawerBackRequests, onLayerChange = { drawerLayerOpen = it }, a = DrawerActions(
|
||||
steam = SessionState.mode == SessionService.MODE_STEAM,
|
||||
direct = noSteamSession(),
|
||||
title = if (SessionState.mode == SessionService.MODE_RUN)
|
||||
com.droiddeck.launcher.frontend.Library.nameForProgram(SessionState.program) ?: getString(R.string.session_title_game) else null,
|
||||
isHomeApp = isHomeApp,
|
||||
androidApps = androidApps,
|
||||
hudOn = hudOn,
|
||||
hudConfig = hudConfig,
|
||||
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
|
||||
effects = effects,
|
||||
cardboard = cardboard,
|
||||
cardboardSensor = hasRotationSensor,
|
||||
onCardboard = { c -> SessionPrefs.setCardboard(this@SessionActivity, c); applyCardboard(c) },
|
||||
onCardboardRecenter = { headTracker?.recenter() },
|
||||
glassesPresent = glasses.present,
|
||||
glassesOutput = glassesOutputActive,
|
||||
onGlassesRecenter = {
|
||||
headTracker?.recenter()
|
||||
com.droiddeck.launcher.glasses.GlassesMenuMirror.recenter()
|
||||
},
|
||||
steamVr = steamVrStatus,
|
||||
immersiveSteamVr = com.droiddeck.launcher.session.QuestExperimental.isSupported(),
|
||||
onSteamVr = { action -> steamVrAction(action) },
|
||||
textureAnisotropy = if (drawerGameProfileId == null) textureAnisotropy else drawerTextureAnisotropy,
|
||||
textureLodBias = if (drawerGameProfileId == null) textureLodBias else drawerTextureLodBias,
|
||||
frameGen = frameGen,
|
||||
lossless = lossless,
|
||||
oscMode = oscMode, onScreenButtonsVisible = onScreenButtonsVisible, suspendPolicy = suspendPolicy,
|
||||
steamDownloadsInBackground = steamDownloadsInBackground, touchMode = touchMode,
|
||||
micAvailable = SessionState.micAvailable && !SessionState.suspended,
|
||||
micEnabled = SessionState.micEnabled,
|
||||
onMicEnabled = { SessionService.setMicEnabled(this@SessionActivity, it) },
|
||||
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
|
||||
fexPreset = fexPreset,
|
||||
secondScreenMode = secondScreenMode,
|
||||
secondScreenDisplays = secondScreenDisplays,
|
||||
selectedSecondScreenDisplay = selectedSecondScreenDisplay,
|
||||
onHud = { on -> SessionPrefs.setHudEnabled(this@SessionActivity, on); hudOn = on; hud.refresh() },
|
||||
onHudSetting = { key, value -> hudConfig = FusionHudConfig.set(this@SessionActivity, key, value); hud.applyConfig() },
|
||||
onHudReset = { hudConfig = FusionHudConfig.reset(this@SessionActivity); hud.applyConfig() },
|
||||
onHudExport = { exportHudDiagnostics() },
|
||||
onUpscaler = { m ->
|
||||
SessionPrefs.setUpscaler(this@SessionActivity, m); upscaler = m
|
||||
WaylandCompositor.nativeSetUpscaler(m)
|
||||
WaylandCompositor.nativeSetLookName(ScreenEffectLooks.match(effects, m)?.name)
|
||||
},
|
||||
onUpscaleSharpness = { pct ->
|
||||
SessionPrefs.setUpscaleSharpness(this@SessionActivity, pct); upscaleSharpness = pct
|
||||
WaylandCompositor.nativeSetUpscaleSharpness(pct)
|
||||
},
|
||||
onEffects = { e ->
|
||||
SessionPrefs.setScreenEffects(this@SessionActivity, e); effects = e
|
||||
e.push(upscaler)
|
||||
},
|
||||
onTextureAnisotropy = { value ->
|
||||
drawerGameProfileId?.let { appId ->
|
||||
SessionPrefs.setGameTextureAnisotropy(this@SessionActivity, appId.toString(), value)
|
||||
drawerTextureAnisotropy = value
|
||||
} ?: value?.let {
|
||||
SessionPrefs.setTextureAnisotropy(this@SessionActivity, it)
|
||||
textureAnisotropy = it
|
||||
}
|
||||
},
|
||||
onTextureLodBias = { value ->
|
||||
drawerGameProfileId?.let { appId ->
|
||||
SessionPrefs.setGameTextureLodBias(this@SessionActivity, appId.toString(), value)
|
||||
drawerTextureLodBias = value
|
||||
} ?: value?.let {
|
||||
SessionPrefs.setTextureLodBias(this@SessionActivity, it)
|
||||
textureLodBias = it
|
||||
}
|
||||
},
|
||||
onFrameGenPick = { mode ->
|
||||
FrameGen.set(this@SessionActivity, mode)
|
||||
readPrefs()
|
||||
applyFrameGen()
|
||||
},
|
||||
onImportLossless = {
|
||||
pickLossless.launch(InAppFilePicker.buildIntent(
|
||||
this@SessionActivity, listOf("dll"), getString(R.string.lsfg_pick_title)))
|
||||
},
|
||||
onKeyboard = { drawerOpen = false; pcKeyboardOpen = false; keyboard?.toggle() },
|
||||
onHardwareKeyboard = ::togglePcKeyboard,
|
||||
controller = controllerSettings,
|
||||
onRumble = { on -> updateControllerPrefs { ControllerPrefs.setRumble(this@SessionActivity, on) } },
|
||||
onSteamButton = { on -> updateControllerPrefs { ControllerPrefs.setSteamButton(this@SessionActivity, on) } },
|
||||
onQamButton = { on -> updateControllerPrefs { ControllerPrefs.setQamButton(this@SessionActivity, on) } },
|
||||
onKeyboardButton = { on -> updateControllerPrefs { ControllerPrefs.setKeyboardButton(this@SessionActivity, on) } },
|
||||
onSteamMenu = if (SessionState.mode == SessionService.MODE_STEAM) ({ sendSteamGuide() }) else null,
|
||||
onQam = if (SessionState.mode == SessionService.MODE_STEAM) ({ triggerSteamQam() }) else null,
|
||||
onAchievements = achievementsInFront?.let { { drawerOpen = false; achievementsOpen = true } },
|
||||
achievementsProgress = achievementsInFront?.progress,
|
||||
padType = if (SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad) padType else null,
|
||||
onPadType = { id ->
|
||||
SessionPrefs.setSteamController(this@SessionActivity, id)
|
||||
com.droiddeck.launcher.session.SteamDeckPad.showPad(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setPadType(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.session.InputSysfsComponent.padTypeChanged(SessionPrefs.padType(id))
|
||||
padType = id
|
||||
},
|
||||
backActionsInverted = backActionsInverted,
|
||||
backDoubleTapMs = backDoubleTapMs,
|
||||
onBackDoubleTapMs = { ms ->
|
||||
SessionPrefs.setBackDoubleTapMs(this@SessionActivity, ms)
|
||||
backDoubleTapMs = ms
|
||||
},
|
||||
onBackActionsInverted = { inverted ->
|
||||
SessionPrefs.setBackActionsInverted(this@SessionActivity, inverted)
|
||||
backActionsInverted = inverted
|
||||
},
|
||||
lowLatency = lowLatency,
|
||||
onLowLatency = { on ->
|
||||
SessionPrefs.setLowLatency(this@SessionActivity, on)
|
||||
lowLatency = on
|
||||
applyLowLatency()
|
||||
},
|
||||
onOsc = { v ->
|
||||
SessionPrefs.setOscMode(this@SessionActivity, v)
|
||||
readPrefs()
|
||||
updateOnScreenControls()
|
||||
if (v == SessionPrefs.OSC_STEAM_TOUCH && com.droiddeck.launcher.input.SteamTouchDevice.current == null)
|
||||
Toast.makeText(this@SessionActivity, R.string.osc_style_next_session, Toast.LENGTH_LONG).show()
|
||||
},
|
||||
onEditSteamTouch = if (steamTouchAvailable && oscMode == SessionPrefs.OSC_STEAM_TOUCH && onScreenButtonsVisible) ({
|
||||
drawerOpen = false
|
||||
steamTouchControls?.startEditing()
|
||||
}) else null,
|
||||
onSuspendPolicy = { policy ->
|
||||
SessionPrefs.setSuspendPolicy(this@SessionActivity, SessionState.mode, policy)
|
||||
suspendPolicy = policy
|
||||
SessionService.suspendPolicyChanged(this@SessionActivity)
|
||||
},
|
||||
onSteamDownloadsInBackground = { enabled ->
|
||||
SessionPrefs.setSteamDownloadsInBackground(this@SessionActivity, enabled)
|
||||
steamDownloadsInBackground = enabled
|
||||
SessionService.suspendPolicyChanged(this@SessionActivity)
|
||||
},
|
||||
onTouch = { v -> SessionPrefs.setTouchMode(this@SessionActivity, v); readPrefs() },
|
||||
onGestureSettings = { drawerOpen = false; gestureSettingsOpen = true },
|
||||
onScreenKeys = { drawerOpen = false; screenKeys?.startEditing() },
|
||||
screenKeysShown = screenKeysShown,
|
||||
onScreenKeysShown = { shown ->
|
||||
screenKeysShown = shown
|
||||
com.droiddeck.launcher.input.ControllerPrefs.setScreenKeysShown(this@SessionActivity, shown)
|
||||
screenKeys?.stopEditing()
|
||||
screenKeys?.visibility = if (shown) View.VISIBLE else View.GONE
|
||||
},
|
||||
onScreenLayouts = {
|
||||
drawerOpen = false
|
||||
screenLayoutNames = layoutNames()
|
||||
screenLayoutsOpen = true
|
||||
},
|
||||
onFexPreset = { v -> SessionPrefs.setFexPreset(this@SessionActivity, v); readPrefs() },
|
||||
onSecondScreenMode = { mode -> if (docked) drawerOpen = false; typingReturnMode = null; selectSecondScreenMode(mode) },
|
||||
onSecondScreenDisplay = ::selectSecondScreenDisplay,
|
||||
onLaunchAndroidApp = { app, displayId ->
|
||||
drawerOpen = false
|
||||
try {
|
||||
HomeApp.launch(this@SessionActivity, app, displayId)
|
||||
} catch (_: Exception) {
|
||||
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)
|
||||
}
|
||||
Toast.makeText(this@SessionActivity, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
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
|
||||
pip.refresh(true)
|
||||
},
|
||||
unfoldedControls = unfoldedControls,
|
||||
onUnfoldedControls = ::chooseUnfoldedControls,
|
||||
unfoldedControlsWithController = unfoldedControlsWithController,
|
||||
onUnfoldedControlsWithController = ::chooseUnfoldedControlsWithController,
|
||||
onBackground = { drawerOpen = false; pip.background(); moveTaskToBack(true) },
|
||||
onShareLogs = { drawerOpen = false; shareCurrentSessionLogs() },
|
||||
onStop = { drawerOpen = false; SessionService.stop(this@SessionActivity); finish() },
|
||||
onStopFrom = { onScreen ->
|
||||
drawerOpen = false
|
||||
if (onScreen == null || com.droiddeck.launcher.ui.Motion.scale == 0f || quitFrom != null) {
|
||||
if (quitFrom == null) { SessionService.stop(this@SessionActivity); finish() }
|
||||
} else {
|
||||
val at = IntArray(2).also { sessionOverlay.getLocationOnScreen(it) }
|
||||
quitFrom = onScreen.translate(-at[0].toFloat(), -at[1].toFloat())
|
||||
}
|
||||
},
|
||||
onClose = { drawerOpen = false },
|
||||
components = drawerComponents,
|
||||
onComponentsRefresh = {
|
||||
refreshDrawerComponents()
|
||||
drawerComponentMenu.refreshComponentCatalog(force = false)
|
||||
},
|
||||
componentCatalog = drawerComponentMenu.compCatalog,
|
||||
componentCatalogAt = drawerComponentMenu.compCatalogAt,
|
||||
componentCatalogChecking = drawerComponentMenu.compChecking,
|
||||
componentDownloads = drawerComponentMenu.compDownloads,
|
||||
componentDownloadRevision = drawerComponentMenu.compDownloadRevision,
|
||||
onComponentCatalogRefresh = { drawerComponentMenu.refreshComponentCatalog() },
|
||||
onComponentDownload = drawerComponentMenu::downloadComponent,
|
||||
gameProfiles = drawerGameProfileRefresh.data?.profiles.orEmpty(),
|
||||
selectedGameProfileId = drawerGameProfileId,
|
||||
selectedGameProfile = drawerGameProfileRefresh.data
|
||||
?.takeIf { it.selectedAppId == drawerGameProfileId }?.profile,
|
||||
gameProfilesLoaded = drawerGameProfileRefresh.loaded,
|
||||
gameProfileRefreshFailed = drawerGameProfileRefresh.failed,
|
||||
onSelectedGameProfile = ::selectDrawerGameProfile,
|
||||
onGameProfilesPageOpened = {
|
||||
drawerGameProfileFollowState.resumeFollowingSteam()
|
||||
drawerGameInventoryRevision++
|
||||
},
|
||||
onSelectedGameProfileRefresh = ::refreshDrawerGameProfile,
|
||||
gameFexPresetSaving = drawerGameFexPresetSaving,
|
||||
onGameFexPreset = ::setDrawerGameFexPreset,
|
||||
gameNoSteamSaving = drawerGameNoSteamSaving,
|
||||
onGameNoSteam = ::setDrawerGameNoSteam,
|
||||
onComponentSwap = { pid, comp, value -> swapDrawerComponent(pid, comp, value) },
|
||||
onGameComponent = ::setDrawerGameComponent,
|
||||
defaultProtonId = drawerDefaultProton,
|
||||
onDefaultProton = ::chooseDrawerDefaultProton,
|
||||
onGameProton = ::setDrawerGameProton,
|
||||
))
|
||||
}
|
||||
|
||||
private fun refreshHomeApp() {
|
||||
isHomeApp = HomeApp.isDefault(this)
|
||||
androidApps = if (isHomeApp) HomeApp.launchableApps(this) else emptyList()
|
||||
@@ -2286,7 +2319,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (pad !== event) return dispatchKeyEvent(pad)
|
||||
val fromController = PadBridge.isControllerKeyEvent(event)
|
||||
if (fromController && event.action == KeyEvent.ACTION_DOWN) {
|
||||
if (drawerOpen && !drawerControllerActive) sessionOverlay.requestFocus()
|
||||
if (drawerOpen && !drawerControllerActive) focusDrawer()
|
||||
drawerControllerActive = true
|
||||
}
|
||||
if (fromController && event.keyCode == KeyEvent.KEYCODE_BUTTON_B && ::loading.isInitialized && loading.visible && !loading.ended && !drawerOpen) {
|
||||
@@ -2326,12 +2359,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
return true
|
||||
}
|
||||
val handled = super.dispatchKeyEvent(event)
|
||||
val handled = dispatchToDrawer(event)
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
Log.i(TAG, "drawer key=${KeyEvent.keyCodeToString(event.keyCode)} handled=$handled viewFocused=${sessionOverlay.hasFocus()}")
|
||||
}
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BUTTON_B || event.keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (!handled && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) drawerOpen = false
|
||||
if (!handled && event.action == KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
if (drawerLayerOpen) drawerBackRequests++ else drawerOpen = false
|
||||
}
|
||||
releaseDrawerDirection()
|
||||
}
|
||||
return true
|
||||
@@ -2383,7 +2418,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
if (pipUi) return true
|
||||
if (drawerOpen && PadBridge.isControllerMotionEvent(event)) {
|
||||
if (!drawerControllerActive) sessionOverlay.requestFocus()
|
||||
if (!drawerControllerActive) focusDrawer()
|
||||
drawerControllerActive = true
|
||||
if (event.actionMasked == MotionEvent.ACTION_MOVE &&
|
||||
event.isFromSource(InputDevice.SOURCE_JOYSTICK)
|
||||
@@ -2481,7 +2516,51 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (action == KeyEvent.ACTION_DOWN && repeatCount == 0) {
|
||||
Log.i(TAG, "drawer synthetic key=${KeyEvent.keyCodeToString(drawerDirectionKey)} viewFocused=${sessionOverlay.hasFocus()}")
|
||||
}
|
||||
super.dispatchKeyEvent(event)
|
||||
dispatchToDrawer(event)
|
||||
}
|
||||
|
||||
private fun dockedMenu(): SecondScreenPresentation? = secondScreenPresentation?.takeIf { drawerDocked && it.menuShown }
|
||||
|
||||
private fun dispatchToDrawer(event: KeyEvent): Boolean {
|
||||
val bottom = dockedMenu()
|
||||
if (bottom != null && event.keyCode != KeyEvent.KEYCODE_BACK) return bottom.dispatchMenuKey(event)
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
private fun focusDrawer(): Boolean = dockedMenu()?.focusMenu() ?: sessionOverlay.requestFocus()
|
||||
|
||||
private fun dockDrawer(): Boolean {
|
||||
if (pipUi || !started || glassesScreen != null || !::displayManager.isInitialized) return false
|
||||
if (!SessionPrefs.dualScreenLauncher(this)) return false
|
||||
val target = com.droiddeck.launcher.input.DualScreen.display(this, displayManager, shownOnDisplayId) ?: return false
|
||||
if (secondScreenDisplays.none { it.id == target.displayId }) return false
|
||||
val shown = secondScreenPresentation?.display?.displayId
|
||||
return shown == null || shown == target.displayId
|
||||
}
|
||||
|
||||
private fun openDockedMenu(): Boolean {
|
||||
val target = com.droiddeck.launcher.input.DualScreen.display(this, displayManager, shownOnDisplayId) ?: return false
|
||||
return try {
|
||||
val presentation = secondScreenPresentation ?: secondScreenPresentation(target).also {
|
||||
selectedSecondScreenDisplay = target.displayId
|
||||
secondScreenPresentation = it
|
||||
}
|
||||
if (!presentation.isShowing) presentation.show()
|
||||
presentation.showMenu(true)
|
||||
updateKeyboardRoute()
|
||||
presentation.menuShown
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "could not open the menu on ${target.name}", e)
|
||||
if (secondScreenMode == SecondScreenMode.NONE) closeSecondScreen(reset = false)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeDockedMenu() {
|
||||
drawerDocked = false
|
||||
val presentation = secondScreenPresentation ?: return
|
||||
presentation.showMenu(false)
|
||||
if (secondScreenMode == SecondScreenMode.NONE) closeSecondScreen(reset = false) else updateKeyboardRoute()
|
||||
}
|
||||
|
||||
private fun layoutNames(): List<String> =
|
||||
@@ -2679,8 +2758,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun refreshSecondScreenDisplays() {
|
||||
if (!::displayManager.isInitialized) return
|
||||
val primaryId = shownOnDisplayId
|
||||
val dualOff = SessionPrefs.dualScreenMode(this) == com.droiddeck.launcher.input.DualScreen.MODE_OFF
|
||||
val candidates = SecondScreenDisplays.available(displayManager, primaryId)
|
||||
.filter { glassesScreen == null || it.id != glasses.displayId }
|
||||
.filter { !dualOff && (glassesScreen == null || it.id != glasses.displayId) }
|
||||
val oldIds = secondScreenDisplays.map { it.id }.toSet()
|
||||
secondScreenDisplays = candidates
|
||||
val newIds = candidates.map { it.id }.toSet()
|
||||
@@ -2691,6 +2771,17 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (selectedSecondScreenDisplay !in newIds) selectedSecondScreenDisplay = candidates.firstOrNull()?.id ?: -1
|
||||
if (secondScreenMode != SecondScreenMode.NONE && candidates.isEmpty()) closeSecondScreen(reset = true)
|
||||
else if (started && secondScreenMode != SecondScreenMode.NONE && secondScreenPresentation == null) showSecondScreen(secondScreenMode)
|
||||
updateKeyboardRoute()
|
||||
}
|
||||
|
||||
private fun openDualScreenControls() {
|
||||
if (SessionState.secondScreenAutoOpened || secondScreenMode != SecondScreenMode.NONE || pipUi) return
|
||||
if (!SessionPrefs.dualScreenSessionControls(this)) return
|
||||
val target = com.droiddeck.launcher.input.DualScreen.display(this, displayManager, shownOnDisplayId) ?: return
|
||||
if (secondScreenDisplays.none { it.id == target.displayId }) return
|
||||
SessionState.secondScreenAutoOpened = true
|
||||
selectedSecondScreenDisplay = target.displayId
|
||||
selectSecondScreenMode(if (SessionState.deckPad) SecondScreenMode.DECK_CONTROLS else SecondScreenMode.KEYBOARD_TRACKPAD)
|
||||
}
|
||||
|
||||
private fun selectSecondScreenDisplay(displayId: Int) {
|
||||
@@ -2724,19 +2815,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
var presentation = secondScreenPresentation
|
||||
if (presentation?.display?.displayId != target.displayId) {
|
||||
dropDockedDrawer()
|
||||
presentation?.closeControls()
|
||||
presentation = SecondScreenPresentation(
|
||||
this, target,
|
||||
sendPointer = ::moveSecondScreenPointer,
|
||||
sendButton = { button, pressed ->
|
||||
WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0)
|
||||
},
|
||||
sendWheel = { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) },
|
||||
onSteamMenu = ::tapSteamButton,
|
||||
onQam = ::tapQam,
|
||||
onClose = { selectSecondScreenMode(SecondScreenMode.NONE) },
|
||||
pad = padBridge,
|
||||
)
|
||||
presentation = secondScreenPresentation(target)
|
||||
secondScreenPresentation = presentation
|
||||
}
|
||||
try {
|
||||
@@ -2745,12 +2826,31 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
secondScreenMode = mode
|
||||
SessionState.secondScreenMode = mode
|
||||
SessionState.secondScreenDisplay = selectedSecondScreenDisplay
|
||||
updateKeyboardRoute()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "could not show second-screen controls on ${target.name}", e)
|
||||
closeSecondScreen(reset = true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun secondScreenPresentation(target: Display) = SecondScreenPresentation(
|
||||
this, target,
|
||||
sendPointer = ::moveSecondScreenPointer,
|
||||
sendButton = { button, pressed ->
|
||||
WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0)
|
||||
},
|
||||
sendWheel = { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) },
|
||||
onSteamMenu = ::tapSteamButton,
|
||||
onQam = ::tapQam,
|
||||
onClose = { selectSecondScreenMode(SecondScreenMode.NONE) },
|
||||
pad = padBridge,
|
||||
onKeyboardClosed = ::bottomKeyboardClosed,
|
||||
onMenu = if (dockDrawer()) ({ drawerOpen = true }) else null,
|
||||
menu = {
|
||||
DroidDeckTheme { SessionMenu(docked = true) }
|
||||
},
|
||||
)
|
||||
|
||||
private fun tapSteamButton() {
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) {
|
||||
padBridge?.applyTouch { st -> st.press(com.droiddeck.launcher.input.PadState.GUIDE, true) }
|
||||
@@ -2833,9 +2933,49 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
showCursor(px, py)
|
||||
}
|
||||
|
||||
private fun openBottomKeyboard() {
|
||||
if (!started) return
|
||||
if (secondScreenPresentation?.showsKeyboard != true && dockDrawer()) {
|
||||
val target = com.droiddeck.launcher.input.DualScreen.display(this, displayManager, shownOnDisplayId) ?: return
|
||||
if (drawerOpen) drawerOpen = false
|
||||
typingReturnMode = secondScreenMode
|
||||
selectedSecondScreenDisplay = target.displayId
|
||||
selectSecondScreenMode(SecondScreenMode.KEYBOARD_TRACKPAD)
|
||||
}
|
||||
val presentation = secondScreenPresentation ?: return
|
||||
if (!presentation.showsKeyboard) return
|
||||
val display = presentation.display?.displayId ?: return
|
||||
presentation.requestKeyboard(forField = true)
|
||||
com.droiddeck.launcher.ui.SessionTyping.focusDisplay(this, display)
|
||||
}
|
||||
|
||||
private fun bottomKeyboardClosed() {
|
||||
com.droiddeck.launcher.ui.SessionTyping.returnFocus(this, taskId)
|
||||
val mode = typingReturnMode ?: return
|
||||
typingReturnMode = null
|
||||
uiHandler.post { if (secondScreenMode == SecondScreenMode.KEYBOARD_TRACKPAD) selectSecondScreenMode(mode) }
|
||||
}
|
||||
|
||||
private fun updateKeyboardRoute() {
|
||||
AgentGuest.routeKeyboard(this, SessionState.mode == SessionService.MODE_STEAM &&
|
||||
(secondScreenPresentation?.showsKeyboard == true || dockDrawer()))
|
||||
}
|
||||
|
||||
private fun dropDockedDrawer() {
|
||||
if (!drawerDocked) return
|
||||
drawerDocked = false
|
||||
drawerLayerOpen = false
|
||||
drawerOpenState = false
|
||||
}
|
||||
|
||||
private fun closeSecondScreen(reset: Boolean) {
|
||||
dropDockedDrawer()
|
||||
val focused = secondScreenPresentation?.window?.decorView?.hasWindowFocus() == true
|
||||
secondScreenPresentation?.closeControls()
|
||||
secondScreenPresentation = null
|
||||
if (focused && started) com.droiddeck.launcher.ui.SessionTyping.returnFocus(this, taskId)
|
||||
else com.droiddeck.launcher.ui.SessionTyping.close()
|
||||
updateKeyboardRoute()
|
||||
if (reset) {
|
||||
secondScreenMode = SecondScreenMode.NONE
|
||||
SessionState.secondScreenMode = SecondScreenMode.NONE
|
||||
@@ -2896,9 +3036,18 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private var ignoreGameTouch = false
|
||||
private var dismissTouch = false
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
|
||||
if (drawerOpen && drawerDocked && event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||
drawerOpen = false
|
||||
dismissTouch = true
|
||||
}
|
||||
if (dismissTouch) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) dismissTouch = false
|
||||
return true
|
||||
}
|
||||
if (drawerOpen || pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || pipUi || SessionState.suspended) return true
|
||||
if (routedTouchMode == SessionPrefs.TOUCH_GESTURES) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) gesturePointerReady = false
|
||||
@@ -3289,6 +3438,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
refreshSecondScreenDisplays()
|
||||
if (secondScreenMode != SecondScreenMode.NONE && secondScreenPresentation == null) showSecondScreen(secondScreenMode)
|
||||
else if (::loading.isInitialized && !loading.visible) openDualScreenControls()
|
||||
startedScreens++
|
||||
SessionService.setActivityVisible(this, true, sessionActivityDisplayId)
|
||||
Glasses.rescan()
|
||||
@@ -3809,6 +3959,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
loading.visible = false
|
||||
hud.start()
|
||||
memoryHud.start()
|
||||
if (started) openDualScreenControls()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ object AgentGuest {
|
||||
private set
|
||||
var steamKeyboard by mutableStateOf(false)
|
||||
private set
|
||||
var keyboardRequests by mutableIntStateOf(0)
|
||||
private set
|
||||
var keyboardDismissals by mutableIntStateOf(0)
|
||||
private set
|
||||
@Volatile private var keyboardRoute = false
|
||||
@Volatile private var routeDir: File? = null
|
||||
private const val TAG = "AgentGuest"
|
||||
private const val POLL_MS = 50L
|
||||
private val lock = Any()
|
||||
@@ -39,6 +45,8 @@ object AgentGuest {
|
||||
val dir = dir(context)
|
||||
dir.deleteRecursively()
|
||||
dir.mkdirs()
|
||||
routeDir = dir
|
||||
writeKeyboardRoute(dir, keyboardRoute)
|
||||
@Suppress("DEPRECATION")
|
||||
observer = object : FileObserver(dir.path, MOVED_TO or CLOSE_WRITE) {
|
||||
override fun onEvent(event: Int, path: String?) {
|
||||
@@ -48,6 +56,8 @@ object AgentGuest {
|
||||
}
|
||||
"focus.json" -> readJson(File(dir, path))?.let(::recordFocus)
|
||||
"keyboard.json" -> readJson(File(dir, path))?.let { recordKeyboard(this, it) }
|
||||
"keyboard-request.json" -> readJson(File(dir, path))?.let { recordKeyboardRequest(this) }
|
||||
"keyboard-dismiss.json" -> readJson(File(dir, path))?.let { recordKeyboardDismiss(this) }
|
||||
}
|
||||
}
|
||||
}.also { it.startWatching() }
|
||||
@@ -62,6 +72,42 @@ object AgentGuest {
|
||||
}
|
||||
}
|
||||
|
||||
fun routeKeyboard(context: Context, bottom: Boolean) {
|
||||
synchronized(lock) {
|
||||
if (keyboardRoute == bottom) return
|
||||
keyboardRoute = bottom
|
||||
writeKeyboardRoute(routeDir ?: dir(context), bottom)
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeKeyboardRoute(dir: File, bottom: Boolean) {
|
||||
val file = File(dir, "keyboard-route")
|
||||
runCatching {
|
||||
if (!bottom) file.delete()
|
||||
else if (dir.isDirectory) {
|
||||
val temp = File(dir, "keyboard-route.tmp")
|
||||
temp.writeText("bottom")
|
||||
if (!temp.renameTo(file)) temp.delete()
|
||||
}
|
||||
}.onFailure { Log.w(TAG, "keyboard route not written", it) }
|
||||
}
|
||||
|
||||
private fun recordKeyboardRequest(source: FileObserver) {
|
||||
synchronized(lock) {
|
||||
if (source !== observer) return
|
||||
main.post { keyboardRequests++ }
|
||||
}
|
||||
SessionEvents.record("keyboard.requested", emptyMap())
|
||||
}
|
||||
|
||||
private fun recordKeyboardDismiss(source: FileObserver) {
|
||||
synchronized(lock) {
|
||||
if (source !== observer) return
|
||||
main.post { keyboardDismissals++ }
|
||||
}
|
||||
SessionEvents.record("keyboard.dismissed", emptyMap())
|
||||
}
|
||||
|
||||
private fun recordKeyboard(source: FileObserver, snapshot: JSONObject) {
|
||||
val showing = snapshot.optBoolean("steamKeyboard")
|
||||
synchronized(lock) {
|
||||
|
||||
@@ -16,6 +16,7 @@ data class GpuInfo(
|
||||
val modelSource: String = "",
|
||||
val kgslChipId: String = "",
|
||||
val platformGpuModel: Int = 0,
|
||||
val verifiedDevice: Boolean = false,
|
||||
) {
|
||||
enum class Family(val label: String) {
|
||||
A8XX("Adreno 8xx"),
|
||||
@@ -36,6 +37,7 @@ data class GpuInfo(
|
||||
get() = when {
|
||||
family == Family.NOT_ADRENO -> Support.UNSUPPORTED
|
||||
isA850 -> Support.UNTESTED
|
||||
verifiedDevice -> Support.TESTED
|
||||
family == Family.A6XX && model == 650 -> Support.TESTED
|
||||
family == Family.A8XX -> Support.TESTED
|
||||
family == Family.A7XX && model >= 725 -> Support.TESTED
|
||||
@@ -85,9 +87,13 @@ data class GpuInfo(
|
||||
oneUi8Gen2 = samsung && model == 740,
|
||||
kgslName = raw.orEmpty(), modelSource = source, kgslChipId = chipId,
|
||||
platformGpuModel = platformGpuModel,
|
||||
verifiedDevice = adreno && verifiedOn(model, Build.MODEL),
|
||||
)
|
||||
}
|
||||
|
||||
internal fun verifiedOn(model: Int, device: String): Boolean =
|
||||
model == 722 && device.equals("Retroid Pocket Duo", ignoreCase = true)
|
||||
|
||||
internal fun threeDigits(text: String): Int = Regex("""(?i)\badreno\s*(?:\(TM\)\s*)?(\d{3})(?!\d)""").find(text)?.groupValues?.get(1)?.toIntOrNull() ?: 0
|
||||
|
||||
internal fun modelFromNames(
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.os.Build
|
||||
import android.view.Display
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
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)
|
||||
private const val TYPE_INTERNAL = 1
|
||||
private val knownModels = setOf("retroid pocket duo", "ayn thor")
|
||||
|
||||
fun builtInDisplay(displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).firstOrNull {
|
||||
it.isValid && it.displayId != primaryDisplayId && (it.flags and Display.FLAG_PRESENTATION) != 0 &&
|
||||
isBuiltIn(displayType(it), Build.MODEL)
|
||||
}
|
||||
|
||||
fun display(context: Context, displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
when (SessionPrefs.dualScreenMode(context)) {
|
||||
MODE_OFF -> null
|
||||
MODE_ON -> builtInDisplay(displayManager, primaryDisplayId) ?: anyDisplay(displayManager, primaryDisplayId)
|
||||
else -> builtInDisplay(displayManager, primaryDisplayId)
|
||||
}
|
||||
|
||||
fun anyDisplay(displayManager: DisplayManager, primaryDisplayId: Int): Display? =
|
||||
displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION).firstOrNull {
|
||||
it.isValid && it.displayId != primaryDisplayId && (it.flags and Display.FLAG_PRESENTATION) != 0
|
||||
}
|
||||
|
||||
internal fun isBuiltIn(type: Int?, model: String): Boolean =
|
||||
if (type != null) type == TYPE_INTERNAL else model.trim().lowercase() in knownModels
|
||||
|
||||
private fun displayType(display: Display): Int? =
|
||||
runCatching { Display::class.java.getMethod("getType").invoke(display) as Int }.getOrNull()
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.os.Build
|
||||
import android.view.KeyEvent
|
||||
|
||||
class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCancel: () -> Unit = {}) {
|
||||
@@ -8,6 +9,10 @@ class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCa
|
||||
|
||||
fun onKeyEvent(event: KeyEvent, enabled: Boolean): Boolean {
|
||||
if (!isHome(event.keyCode)) return false
|
||||
if (isQuickMenuKey(event)) {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) cancel()
|
||||
return false
|
||||
}
|
||||
if (!enabled) cancel()
|
||||
val device = event.deviceId
|
||||
return when (event.action) {
|
||||
@@ -43,5 +48,10 @@ class HomeGuideInput(private val setPressed: (Boolean) -> Unit, private val onCa
|
||||
companion object {
|
||||
// The Retroid Nova pad falls back to Generic.kl, which maps its Home scan code to MOVE_HOME.
|
||||
fun isHome(keyCode: Int) = keyCode == KeyEvent.KEYCODE_HOME || keyCode == KeyEvent.KEYCODE_MOVE_HOME
|
||||
|
||||
private const val DUO_QUICK_MENU_SCAN_CODE = 194
|
||||
|
||||
fun isQuickMenuKey(event: KeyEvent) =
|
||||
event.scanCode == DUO_QUICK_MENU_SCAN_CODE && "Retroid Pocket Duo".equals(Build.MODEL, ignoreCase = true)
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,26 @@ object SessionPrefs {
|
||||
prefs(context).edit().putBoolean("animations", on).apply()
|
||||
}
|
||||
|
||||
fun dualScreenMode(context: Context): String =
|
||||
prefs(context).getString("dualScreenMode", null)?.takeIf { it in com.droiddeck.launcher.input.DualScreen.modes }
|
||||
?: com.droiddeck.launcher.input.DualScreen.MODE_AUTO
|
||||
|
||||
fun setDualScreenMode(context: Context, mode: String) {
|
||||
prefs(context).edit().putString("dualScreenMode", mode).apply()
|
||||
}
|
||||
|
||||
fun dualScreenLauncher(context: Context): Boolean = prefs(context).getBoolean("dualScreenLauncher", true)
|
||||
|
||||
fun setDualScreenLauncher(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("dualScreenLauncher", on).apply()
|
||||
}
|
||||
|
||||
fun dualScreenSessionControls(context: Context): Boolean = prefs(context).getBoolean("dualScreenSessionControls", true)
|
||||
|
||||
fun setDualScreenSessionControls(context: Context, on: Boolean) {
|
||||
prefs(context).edit().putBoolean("dualScreenSessionControls", on).apply()
|
||||
}
|
||||
|
||||
fun gameStoresEnabled(context: Context): Boolean = prefs(context).getBoolean("gameStoresEnabled", true)
|
||||
|
||||
fun setGameStoresEnabled(context: Context, on: Boolean) {
|
||||
|
||||
@@ -546,6 +546,7 @@ class SessionService : Service() {
|
||||
val fakeInputDir = File(sessionRoot, "dev/input").apply { mkdirs() }
|
||||
val controllersOn = !File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()
|
||||
SessionState.deckPad = false
|
||||
SessionState.secondScreenAutoOpened = false
|
||||
deckBinds = emptyList()
|
||||
inputSysfs = null
|
||||
if (controllersOn) {
|
||||
@@ -1882,6 +1883,9 @@ class SessionService : Service() {
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
if (rootIntent?.component?.className in setOf(
|
||||
com.droiddeck.launcher.ui.DualScreenActivity::class.java.name,
|
||||
com.droiddeck.launcher.ui.SessionTypingActivity::class.java.name)) return
|
||||
if (pipTask || xrActivityVisible) {
|
||||
Log.i(TAG, "panel task dismissed - retaining the session under its active surface policy")
|
||||
activityVisible = false
|
||||
|
||||
@@ -91,6 +91,7 @@ object SessionState {
|
||||
|
||||
@Volatile var secondScreenMode = com.droiddeck.launcher.input.SecondScreenMode.NONE
|
||||
@Volatile var secondScreenDisplay = -1
|
||||
@Volatile var secondScreenAutoOpened = false
|
||||
|
||||
@Volatile
|
||||
var mode = "steam"
|
||||
|
||||
@@ -12,6 +12,7 @@ object SettingsReset {
|
||||
|
||||
internal val SESSION_KEYS = setOf(
|
||||
"orientation", "launcherFullscreen", "animations", "theme", "runSteamAtStartup", "addedGamesArt",
|
||||
"dualScreenMode", "dualScreenLauncher", "dualScreenSessionControls",
|
||||
"gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
|
||||
"storesInstallLanguage",
|
||||
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "fusionHud", "fusionHudPos", "backActionsInverted", "backDoubleTapMs", "touch", "osc", "shape", "steamController",
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.CommitTextCommand
|
||||
import androidx.compose.ui.text.input.DeleteAllCommand
|
||||
import androidx.compose.ui.text.input.EditCommand
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.PlatformTextInputService
|
||||
import androidx.compose.ui.text.input.SetSelectionCommand
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.input.TextInputService
|
||||
import androidx.compose.ui.text.input.TextInputSession
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
class TypingRequest(
|
||||
initial: TextFieldValue,
|
||||
val imeOptions: ImeOptions,
|
||||
private val onValue: (TextFieldValue) -> Unit,
|
||||
private val onImeAction: (ImeAction) -> Unit,
|
||||
private val onClose: () -> Unit = {},
|
||||
) {
|
||||
var value by mutableStateOf(initial)
|
||||
|
||||
fun send(next: TextFieldValue) {
|
||||
value = next
|
||||
onValue(next)
|
||||
}
|
||||
|
||||
fun action() = onImeAction(imeOptions.imeAction)
|
||||
|
||||
fun close() = onClose()
|
||||
|
||||
companion object {
|
||||
internal fun editsFor(next: TextFieldValue): List<EditCommand> = listOf(
|
||||
DeleteAllCommand(),
|
||||
CommitTextCommand(next.text, 1),
|
||||
SetSelectionCommand(next.selection.start, next.selection.end),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal val LocalBottomTyping = staticCompositionLocalOf { false }
|
||||
|
||||
internal class BottomScreenTextInput(private val fallback: TextInputService) : PlatformTextInputService {
|
||||
private var session: TextInputSession? = null
|
||||
|
||||
override fun startInput(
|
||||
value: TextFieldValue, imeOptions: ImeOptions,
|
||||
onEditCommand: (List<EditCommand>) -> Unit, onImeActionPerformed: (ImeAction) -> Unit,
|
||||
) {
|
||||
session?.let { fallback.stopInput(it) }
|
||||
session = null
|
||||
if (DualScreenPanel.attached) DualScreenPanel.startTyping(TypingRequest(value, imeOptions, { onEditCommand(TypingRequest.editsFor(it)) }, onImeActionPerformed))
|
||||
else session = fallback.startInput(value, imeOptions, onEditCommand, onImeActionPerformed)
|
||||
}
|
||||
|
||||
override fun stopInput() {
|
||||
session?.let { fallback.stopInput(it) }
|
||||
session = null
|
||||
DualScreenPanel.stopTyping()
|
||||
}
|
||||
|
||||
override fun showSoftwareKeyboard() {
|
||||
val active = session
|
||||
if (active != null) active.showSoftwareKeyboard() else DualScreenPanel.showTyping()
|
||||
}
|
||||
|
||||
override fun hideSoftwareKeyboard() {
|
||||
val active = session
|
||||
if (active != null) active.hideSoftwareKeyboard() else DualScreenPanel.hideTyping()
|
||||
}
|
||||
|
||||
override fun updateState(oldValue: TextFieldValue?, newValue: TextFieldValue) {
|
||||
val active = session
|
||||
if (active != null) active.updateState(oldValue, newValue) else DualScreenPanel.updateTyping(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun TypingPanel(request: TypingRequest, onDone: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var field by remember(request) { mutableStateOf(request.value) }
|
||||
LaunchedEffect(request.value) {
|
||||
if (request.value.text != field.text) field = request.value
|
||||
}
|
||||
val focus = remember { FocusRequester() }
|
||||
val keyboard = LocalSoftwareKeyboardController.current
|
||||
LaunchedEffect(request) {
|
||||
kotlinx.coroutines.delay(120)
|
||||
runCatching { focus.requestFocus() }
|
||||
keyboard?.show()
|
||||
}
|
||||
val options = request.imeOptions
|
||||
val secret = options.keyboardType == KeyboardType.Password || options.keyboardType == KeyboardType.NumberPassword
|
||||
Column(
|
||||
Modifier.fillMaxSize().background(colors.background).padding(horizontal = 20.dp, vertical = 14.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(stringResource(R.string.dual_typing_title), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = colors.onSurfaceVariant, modifier = Modifier.weight(1f))
|
||||
Button(onClick = onDone, modifier = Modifier.testTag("dual-typing-done")) { Text(stringResource(R.string.dual_typing_done)) }
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = field,
|
||||
onValueChange = { next ->
|
||||
field = next
|
||||
request.send(next)
|
||||
},
|
||||
singleLine = options.singleLine,
|
||||
maxLines = if (options.singleLine) 1 else 4,
|
||||
textStyle = MaterialTheme.typography.titleLarge,
|
||||
visualTransformation = if (secret) PasswordVisualTransformation() else VisualTransformation.None,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = options.capitalization, autoCorrect = options.autoCorrect,
|
||||
keyboardType = options.keyboardType, imeAction = options.imeAction,
|
||||
),
|
||||
keyboardActions = KeyboardActions(onAny = {
|
||||
request.action()
|
||||
onDone()
|
||||
}),
|
||||
modifier = Modifier.fillMaxWidth().focusRequester(focus).testTag("dual-typing-field"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ class DeckControlsPanel(
|
||||
private val onQam: () -> Unit,
|
||||
private val pad: PadBridge? = null,
|
||||
private val portraitDock: Boolean = false,
|
||||
private val onMenu: (() -> Unit)? = null,
|
||||
) : LinearLayout(context) {
|
||||
private enum class Tab(val label: Int) { GAMEPAD(R.string.deck_tab_gamepad), GRIPS(R.string.deck_tab_grips), LEFT(R.string.deck_tab_left), RIGHT(R.string.deck_tab_right), BOTH(R.string.deck_tab_both) }
|
||||
|
||||
@@ -90,6 +91,10 @@ class DeckControlsPanel(
|
||||
addView(tabs, FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, dp(44)))
|
||||
}
|
||||
addView(centre, LayoutParams(0, LayoutParams.MATCH_PARENT, 1f))
|
||||
onMenu?.let {
|
||||
addView(menuButton(context, it))
|
||||
addView(space(dp(8)))
|
||||
}
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) {
|
||||
addView(roundButton("STEAM", context.getString(R.string.deck_open_steam_menu), onSteamMenu, wide = true))
|
||||
addView(space(dp(8)))
|
||||
@@ -250,38 +255,19 @@ class DeckControlsPanel(
|
||||
}
|
||||
|
||||
private fun roundButton(label: String, description: String, onClick: () -> Unit, wide: Boolean = false) =
|
||||
TextView(context).apply {
|
||||
text = label
|
||||
contentDescription = description
|
||||
textSize = if (wide) 13f else 20f
|
||||
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
|
||||
letterSpacing = if (wide) 0.08f else 0f
|
||||
gravity = Gravity.CENTER
|
||||
setTextColor(TEXT)
|
||||
background = outline(CORNER_PILL, SURFACE)
|
||||
setPadding(if (wide) dp(16) else 0, 0, if (wide) dp(16) else 0, 0)
|
||||
minWidth = dp(44)
|
||||
layoutParams = LayoutParams(if (wide) LayoutParams.WRAP_CONTENT else dp(44), dp(44))
|
||||
setOnClickListener {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
roundButton(context, label, description, onClick, wide)
|
||||
|
||||
private fun space(width: Int) = View(context).apply { layoutParams = LayoutParams(width, 1) }
|
||||
|
||||
private fun outline(radius: Float, fill: Int) = GradientDrawable().apply {
|
||||
cornerRadius = radius * resources.displayMetrics.density
|
||||
setColor(fill)
|
||||
setStroke(dp(1), LINE)
|
||||
}
|
||||
private fun outline(radius: Float, fill: Int) = outline(context, radius, fill)
|
||||
|
||||
private fun filled(radius: Float, fill: Int) = GradientDrawable().apply {
|
||||
cornerRadius = radius * resources.displayMetrics.density
|
||||
setColor(fill)
|
||||
}
|
||||
|
||||
private fun dp(value: Int): Int = (value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
private fun dp(value: Int): Int = dp(context, value)
|
||||
|
||||
|
||||
private abstract class Surface(context: Context) : View(context) {
|
||||
protected val density = resources.displayMetrics.density
|
||||
@@ -686,5 +672,47 @@ class DeckControlsPanel(
|
||||
private val TEXT = Color.rgb(0xF2, 0xF4, 0xF7)
|
||||
private val TEXT_DIM = Color.rgb(0x7A, 0x80, 0x8A)
|
||||
private val KNOB = Color.rgb(0x2A, 0x2D, 0x33)
|
||||
|
||||
internal fun dp(context: Context, value: Int): Int = (value * context.resources.displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
internal fun outline(context: Context, radius: Float, fill: Int) = GradientDrawable().apply {
|
||||
cornerRadius = radius * context.resources.displayMetrics.density
|
||||
setColor(fill)
|
||||
setStroke(dp(context, 1), LINE)
|
||||
}
|
||||
|
||||
internal fun roundButton(context: Context, label: String, description: String, onClick: () -> Unit, wide: Boolean = false) =
|
||||
TextView(context).apply {
|
||||
text = label
|
||||
contentDescription = description
|
||||
textSize = if (wide) 13f else 20f
|
||||
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
|
||||
letterSpacing = if (wide) 0.08f else 0f
|
||||
gravity = Gravity.CENTER
|
||||
setTextColor(TEXT)
|
||||
background = outline(context, CORNER_PILL, SURFACE)
|
||||
setPadding(if (wide) dp(context, 16) else 0, 0, if (wide) dp(context, 16) else 0, 0)
|
||||
minWidth = dp(context, 44)
|
||||
layoutParams = LinearLayout.LayoutParams(if (wide) LinearLayout.LayoutParams.WRAP_CONTENT else dp(context, 44), dp(context, 44))
|
||||
setOnClickListener {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun menuButton(context: Context, onClick: () -> Unit) = android.widget.ImageView(context).apply {
|
||||
setImageResource(R.drawable.ic_stat_session)
|
||||
setColorFilter(TEXT)
|
||||
contentDescription = context.getString(R.string.touch_droiddeck_menu)
|
||||
scaleType = android.widget.ImageView.ScaleType.CENTER_INSIDE
|
||||
val pad = dp(context, 11)
|
||||
setPadding(pad, pad, pad, pad)
|
||||
background = outline(context, CORNER_PILL, SURFACE)
|
||||
layoutParams = LinearLayout.LayoutParams(dp(context, 44), dp(context, 44))
|
||||
setOnClickListener {
|
||||
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
|
||||
class DualPanelModel(
|
||||
val keys: List<String>,
|
||||
val selected: String,
|
||||
val badges: Set<String>,
|
||||
val storeDownloads: Int,
|
||||
val running: String?,
|
||||
val theme: String,
|
||||
val appScale: Int,
|
||||
val onSelect: (String) -> Unit,
|
||||
val onResume: () -> Unit,
|
||||
)
|
||||
|
||||
object DualScreenPanel {
|
||||
var model by mutableStateOf<DualPanelModel?>(null)
|
||||
private var displayId = -1
|
||||
private var activity: DualScreenActivity? = null
|
||||
set(value) { field = value; available = value != null || launching }
|
||||
private var launching = false
|
||||
set(value) { field = value; available = value || activity != null }
|
||||
private var ownerTask = -1
|
||||
|
||||
var typing by mutableStateOf<TypingRequest?>(null)
|
||||
private set
|
||||
var typingShown by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
val shownOn: Int get() = if (activity != null || launching) displayId else -1
|
||||
val attached: Boolean get() = activity != null
|
||||
var available by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
fun startTyping(request: TypingRequest) {
|
||||
typing = request
|
||||
typingShown = true
|
||||
}
|
||||
|
||||
fun stopTyping() {
|
||||
typing = null
|
||||
typingShown = false
|
||||
}
|
||||
|
||||
fun stopTyping(request: TypingRequest) {
|
||||
if (typing === request) stopTyping()
|
||||
}
|
||||
|
||||
fun showTyping() {
|
||||
if (typing != null) typingShown = true
|
||||
}
|
||||
|
||||
fun finishTyping() {
|
||||
val request = typing
|
||||
hideTyping()
|
||||
request?.close()
|
||||
}
|
||||
|
||||
fun hideTyping() {
|
||||
typingShown = false
|
||||
}
|
||||
|
||||
fun updateTyping(value: TextFieldValue) {
|
||||
val request = typing ?: return
|
||||
if (request.value != value) request.value = value
|
||||
}
|
||||
|
||||
fun show(context: Context, display: Int, task: Int) {
|
||||
if (shownOn == display) return
|
||||
hide()
|
||||
displayId = display
|
||||
ownerTask = task
|
||||
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)
|
||||
runCatching {
|
||||
context.startActivity(intent, ActivityOptions.makeBasic().setLaunchDisplayId(display).toBundle())
|
||||
}.onFailure { launching = false; displayId = -1 }
|
||||
}
|
||||
|
||||
fun hide() {
|
||||
stopTyping()
|
||||
launching = false
|
||||
displayId = -1
|
||||
activity?.finishAndRemoveTask()
|
||||
activity = null
|
||||
}
|
||||
|
||||
internal fun attach(host: DualScreenActivity): Boolean {
|
||||
if (!launching && activity == null) return false
|
||||
if (activity !== host) activity?.finishAndRemoveTask()
|
||||
activity = host
|
||||
launching = false
|
||||
return true
|
||||
}
|
||||
|
||||
internal fun returnFocus(context: Context) {
|
||||
val task = ownerTask.takeIf { it >= 0 } ?: return
|
||||
runCatching { (context.getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager).moveTaskToFront(task, 0) }
|
||||
}
|
||||
|
||||
internal fun detach(host: DualScreenActivity) {
|
||||
if (activity === host) {
|
||||
activity = null
|
||||
displayId = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DualScreenActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (!DualScreenPanel.attach(this)) {
|
||||
finishAndRemoveTask()
|
||||
return
|
||||
}
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
applyImmersiveMode()
|
||||
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 ?: com.droiddeck.launcher.core.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun acceptFocus(on: Boolean) {
|
||||
if (on) {
|
||||
unfocusPending = false
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
|
||||
runCatching { (getSystemService(ACTIVITY_SERVICE) as android.app.ActivityManager).moveTaskToFront(taskId, 0) }
|
||||
} else {
|
||||
unfocusPending = true
|
||||
DualScreenPanel.returnFocus(this)
|
||||
window.decorView.postDelayed({
|
||||
if (!unfocusPending || DualScreenPanel.typingShown) return@postDelayed
|
||||
if (window.decorView.hasWindowFocus()) DualScreenPanel.returnFocus(this) else dropFocus()
|
||||
}, 400)
|
||||
}
|
||||
}
|
||||
|
||||
private var unfocusPending = false
|
||||
|
||||
private fun dropFocus() {
|
||||
unfocusPending = false
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!DualScreenPanel.typingShown) DualScreenPanel.returnFocus(this)
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) applyImmersiveMode()
|
||||
else if (unfocusPending && !DualScreenPanel.typingShown) dropFocus()
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
DualScreenPanel.detach(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DualPanelContent(model: DualPanelModel) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
Column(Modifier.fillMaxSize().padding(horizontal = 20.dp, vertical = 16.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(stringResource(R.string.app_name), fontSize = 15.sp, fontWeight = FontWeight.Bold, color = pal.signal)
|
||||
Spacer(Modifier.size(12.dp))
|
||||
val (label, _) = railLabelIcon(model.selected)
|
||||
Text(stringResource(label), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground,
|
||||
modifier = Modifier.weight(1f), maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
PanelClock()
|
||||
}
|
||||
BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) {
|
||||
val columns = if (model.keys.size > 6) 4 else 3
|
||||
val rows = (model.keys.size + columns - 1) / columns
|
||||
val gap = 12.dp
|
||||
val tileHeight = ((maxHeight - gap * (rows - 1)) / rows).coerceAtLeast(64.dp)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(gap)) {
|
||||
for (row in model.keys.chunked(columns)) {
|
||||
Row(Modifier.fillMaxWidth().height(tileHeight), horizontalArrangement = Arrangement.spacedBy(gap)) {
|
||||
for (key in row) PanelTile(key, key == model.selected, key in model.badges,
|
||||
if (key == "stores") model.storeDownloads else 0, Modifier.weight(1f)) { model.onSelect(key) }
|
||||
repeat(columns - row.size) { Spacer(Modifier.weight(1f)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (model.running != null) {
|
||||
Row(
|
||||
Modifier.fillMaxWidth().height(56.dp).clip(RoundedCornerShape(16.dp)).background(pal.good.copy(alpha = 0.18f))
|
||||
.clickable(role = Role.Button, onClick = model.onResume).testTag("dual-resume").padding(horizontal = 18.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(Modifier.size(10.dp).clip(CircleShape).background(pal.good))
|
||||
Spacer(Modifier.size(12.dp))
|
||||
Text(stringResource(R.string.rail_resume_named, model.running), fontSize = 16.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PanelTile(key: String, current: Boolean, badge: Boolean, count: Int, modifier: Modifier, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val (label, icon) = railLabelIcon(key)
|
||||
val shape = RoundedCornerShape(18.dp)
|
||||
Box(
|
||||
modifier.fillMaxSize().clip(shape)
|
||||
.background(if (current) pal.signal.copy(alpha = 0.16f) else colors.surface)
|
||||
.border(if (current) 2.dp else 1.dp, if (current) pal.signal else Color.White.copy(alpha = 0.06f), shape)
|
||||
.clickable(role = Role.Tab, onClick = onClick).testTag("dual-rail-$key"),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Icon(icon, contentDescription = null, tint = if (current) pal.signal else colors.onSurfaceVariant, modifier = Modifier.size(34.dp))
|
||||
Text(stringResource(label), fontSize = 15.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (current) pal.signal else colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.padding(horizontal = 6.dp))
|
||||
}
|
||||
if (badge) Box(Modifier.align(Alignment.TopEnd).padding(12.dp).size(10.dp).clip(CircleShape).background(AttentionAmber))
|
||||
if (count > 0) Text(
|
||||
if (count > 9) "9+" else count.toString(), fontSize = 12.sp, fontWeight = FontWeight.Bold, color = pal.onSignal,
|
||||
modifier = Modifier.align(Alignment.TopEnd).padding(10.dp).clip(RoundedCornerShape(8.dp)).background(pal.signal)
|
||||
.padding(horizontal = 6.dp, vertical = 1.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PanelClock() {
|
||||
val context = LocalContext.current
|
||||
var now by remember { mutableStateOf(System.currentTimeMillis()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
now = System.currentTimeMillis()
|
||||
kotlinx.coroutines.delay(60_000L - now % 60_000L)
|
||||
}
|
||||
}
|
||||
Text(android.text.format.DateFormat.getTimeFormat(context).format(java.util.Date(now)), fontSize = 15.sp,
|
||||
fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DualPanelPublisher(s: FrontEndState, selected: String, onSelect: (String) -> Unit, a: FrontEndActions) {
|
||||
val badges = buildSet {
|
||||
if (setupNeedsAttention(s)) add("setup")
|
||||
if (s.updates.hasUpdate) add("updates")
|
||||
}
|
||||
val model = DualPanelModel(navigationKeys(s), selected, badges, s.storeDownloadsActive, s.running, s.theme, s.appScale, onSelect, a.onResume)
|
||||
androidx.compose.runtime.SideEffect { DualScreenPanel.model = model }
|
||||
androidx.compose.runtime.DisposableEffect(Unit) { onDispose { DualScreenPanel.model = null } }
|
||||
}
|
||||
|
||||
internal fun dualPageStep(event: android.view.KeyEvent): Int? = when (event.keyCode) {
|
||||
android.view.KeyEvent.KEYCODE_BUTTON_L2 -> -1
|
||||
android.view.KeyEvent.KEYCODE_BUTTON_R2 -> 1
|
||||
else -> null
|
||||
}
|
||||
@@ -191,24 +191,28 @@ internal fun SideRail(
|
||||
}
|
||||
}
|
||||
|
||||
internal fun railLabelIcon(key: String): Pair<Int, ImageVector> = when (key) {
|
||||
"steam" -> R.string.rail_steam to Icons.Outlined.SportsEsports
|
||||
"games" -> R.string.rail_games to Icons.Outlined.VideoLibrary
|
||||
"stores" -> R.string.rail_stores to Icons.Outlined.LocalMall
|
||||
"desktop" -> R.string.rail_desktop to Icons.Outlined.DesktopWindows
|
||||
"components" -> R.string.rail_components to Icons.Outlined.Layers
|
||||
"android-apps" -> R.string.rail_apps to Icons.Outlined.Apps
|
||||
"setup" -> R.string.rail_setup to Icons.Outlined.Tune
|
||||
else -> R.string.rail_updates to Icons.Outlined.SystemUpdate
|
||||
}
|
||||
|
||||
internal fun setupNeedsAttention(s: FrontEndState): Boolean = !s.ready || (s.available != null && s.available != s.installed) ||
|
||||
PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
|
||||
|
||||
@Composable
|
||||
private fun NavigationItems(
|
||||
s: FrontEndState, shown: String, compact: Boolean, iconOnly: Boolean, height: Dp, width: Dp,
|
||||
place: (String) -> Modifier, onSelect: (String) -> Unit, onFocusSelect: (String) -> Unit,
|
||||
) {
|
||||
val setupNeedsAttention = !s.ready || (s.available != null && s.available != s.installed) ||
|
||||
PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
|
||||
val setupNeedsAttention = setupNeedsAttention(s)
|
||||
for (key in navigationKeys(s)) {
|
||||
val (label, icon) = when (key) {
|
||||
"steam" -> R.string.rail_steam to Icons.Outlined.SportsEsports
|
||||
"games" -> R.string.rail_games to Icons.Outlined.VideoLibrary
|
||||
"stores" -> R.string.rail_stores to Icons.Outlined.LocalMall
|
||||
"desktop" -> R.string.rail_desktop to Icons.Outlined.DesktopWindows
|
||||
"components" -> R.string.rail_components to Icons.Outlined.Layers
|
||||
"android-apps" -> R.string.rail_apps to Icons.Outlined.Apps
|
||||
"setup" -> R.string.rail_setup to Icons.Outlined.Tune
|
||||
else -> R.string.rail_updates to Icons.Outlined.SystemUpdate
|
||||
}
|
||||
val (label, icon) = railLabelIcon(key)
|
||||
key(key) {
|
||||
RailItem(stringResource(label), icon, key, shown == key, compact, iconOnly, height, width,
|
||||
badge = (key == "setup" && setupNeedsAttention) || (key == "updates" && s.updates.hasUpdate),
|
||||
|
||||
@@ -69,6 +69,9 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.platform.LocalInputModeManager
|
||||
import androidx.compose.ui.input.InputMode
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
@@ -127,6 +130,11 @@ class FrontEndState(
|
||||
val integrationFocus: com.droiddeck.launcher.core.SteamIntegration.Feature? = null,
|
||||
val androidApps: List<HomeApp.LaunchableApp> = emptyList(),
|
||||
val secondScreenDisplays: List<SecondScreenDisplay> = emptyList(),
|
||||
val dualScreen: Boolean = false,
|
||||
val dualScreenDevice: Boolean = false,
|
||||
val dualScreenMode: String = com.droiddeck.launcher.input.DualScreen.MODE_AUTO,
|
||||
val dualScreenLauncher: Boolean = true,
|
||||
val dualScreenControls: Boolean = true,
|
||||
val packages: List<PackageRow>? = null,
|
||||
val packageCatalogLoading: Boolean = false,
|
||||
val packageBusyId: String? = null,
|
||||
@@ -229,6 +237,9 @@ class FrontEndActions(
|
||||
val onLauncherOrientation: (Int) -> Unit = {},
|
||||
val onLauncherFullscreen: (Boolean) -> Unit = {},
|
||||
val onAnimationsEnabled: (Boolean) -> Unit = {},
|
||||
val onDualScreenMode: (String) -> Unit = {},
|
||||
val onDualScreenLauncher: (Boolean) -> Unit = {},
|
||||
val onDualScreenControls: (Boolean) -> Unit = {},
|
||||
val onDownloadSource: (String) -> Unit = {},
|
||||
val onDownloadMirror: (String) -> Unit = {},
|
||||
val onDownloadPrefix: (String) -> Unit = {},
|
||||
@@ -401,10 +412,14 @@ internal suspend fun focusSoon(target: () -> FocusRequester) {
|
||||
@Composable
|
||||
fun FrontEndScreen(s: FrontEndState, a: FrontEndActions, page: (@Composable () -> Unit)? = null) {
|
||||
val frontFocus = remember { FrontFocus() }
|
||||
val textInput = androidx.compose.ui.platform.LocalTextInputService.current
|
||||
val bottomTextInput = remember(textInput) { textInput?.let { androidx.compose.ui.text.input.TextInputService(BottomScreenTextInput(it)) } }
|
||||
androidx.compose.foundation.layout.BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
CompositionLocalProvider(
|
||||
LocalFrontFocus provides frontFocus,
|
||||
LocalNarrowPane provides (maxWidth < NarrowPaneWidth),
|
||||
androidx.compose.ui.platform.LocalTextInputService provides (if (s.dualScreen) bottomTextInput else textInput),
|
||||
LocalBottomTyping provides s.dualScreen,
|
||||
) { FrontEndScreenBody(s, a, page, frontFocus) }
|
||||
}
|
||||
}
|
||||
@@ -550,6 +565,18 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
val window = LocalWindowInfo.current
|
||||
val androidContext = androidx.compose.ui.platform.LocalContext.current
|
||||
var anyFocused by remember { mutableStateOf(false) }
|
||||
val paneRequester = remember { FocusRequester() }
|
||||
val focusManager = androidx.compose.ui.platform.LocalFocusManager.current
|
||||
suspend fun focusDualPane() {
|
||||
repeat(30) {
|
||||
withFrameNanos { }
|
||||
if (anyFocused) return
|
||||
runCatching { paneRequester.requestFocus() }
|
||||
if (anyFocused) return
|
||||
focusManager.moveFocus(FocusDirection.Down)
|
||||
if (anyFocused) return
|
||||
}
|
||||
}
|
||||
androidx.compose.foundation.layout.BoxWithConstraints(
|
||||
modifier = Modifier.fillMaxSize().background(colors.background)
|
||||
.windowInsetsPadding(if (s.launcherFullscreen) WindowInsets.displayCutout else WindowInsets.systemBars)
|
||||
@@ -560,7 +587,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
if (processSettingsPageVisible) return@LaunchedEffect
|
||||
snapshotFlow { window.isWindowFocused }.first { it }
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard)
|
||||
focusWithinFrames({ anyFocused }) { if (frontFocus.primaryAttached > 0) frontFocus.primary else frontFocus.railFor(railSelection) }
|
||||
if (s.dualScreen && frontFocus.primaryAttached == 0) focusDualPane()
|
||||
else focusWithinFrames({ anyFocused }) { if (frontFocus.primaryAttached > 0) frontFocus.primary else frontFocus.railFor(railSelection) }
|
||||
}
|
||||
var openPage by remember { mutableStateOf<String?>(null) }
|
||||
LaunchedEffect(s.pageKey) {
|
||||
@@ -582,16 +610,22 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
return@LaunchedEffect
|
||||
}
|
||||
if (anyFocused) return@LaunchedEffect
|
||||
focusWithinFrames({ anyFocused }) { if (frontFocus.primaryAttached > 0) frontFocus.primary else frontFocus.railFor(railSelection) }
|
||||
if (s.dualScreen && frontFocus.primaryAttached == 0) focusDualPane()
|
||||
else focusWithinFrames({ anyFocused }) { if (frontFocus.primaryAttached > 0) frontFocus.primary else frontFocus.railFor(railSelection) }
|
||||
}
|
||||
LaunchedEffect(railPicks) {
|
||||
if (railPicks == 0 || processSettingsPageVisible) return@LaunchedEffect
|
||||
kotlinx.coroutines.delay(Motion.ms(PAGE_EXIT_MS).toLong())
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
withTimeoutOrNull(1_000) { snapshotFlow { frontFocus.primaryAttached > 0 }.first { it } } ?: return@LaunchedEffect
|
||||
val entry = withTimeoutOrNull(1_000) { snapshotFlow { frontFocus.primaryAttached > 0 }.first { it } }
|
||||
if (entry == null) {
|
||||
if (s.dualScreen) focusDualPane()
|
||||
return@LaunchedEffect
|
||||
}
|
||||
focusWithinFrames({ frontFocus.focusedRail == null && anyFocused }) { frontFocus.paneEntry() }
|
||||
}
|
||||
val paneFocus = Modifier
|
||||
.focusRequester(paneRequester)
|
||||
.focusProperties {
|
||||
enter = { frontFocus.paneEntry() }
|
||||
exit = { direction ->
|
||||
@@ -617,12 +651,31 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
focusWithinFrames({ frontFocus.last == r.control && anyFocused }) { frontFocus.items[r.control] ?: frontFocus.paneEntry() }
|
||||
}
|
||||
var screenAt by remember { mutableStateOf(Offset.Zero) }
|
||||
if (s.dualScreen) DualPanelPublisher(s, railSelection, { key ->
|
||||
if (processSettingsPageVisible) return@DualPanelPublisher
|
||||
if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard)
|
||||
focusManager.clearFocus(force = true)
|
||||
onRailSelect(key)
|
||||
}, a)
|
||||
CompositionLocalProvider(LocalShowSection provides { key -> selected = key }) {
|
||||
LauncherLayout(
|
||||
bottomNavigation, pal.line,
|
||||
Modifier.fillMaxSize().onGloballyPositioned { screenAt = it.positionInRoot() },
|
||||
bottomNavigation && !s.dualScreen, pal.line,
|
||||
Modifier.fillMaxSize().onGloballyPositioned { screenAt = it.positionInRoot() }
|
||||
.then(if (s.dualScreen) Modifier.onKeyEvent { event ->
|
||||
val step = dualPageStep(event.nativeKeyEvent) ?: return@onKeyEvent false
|
||||
if (event.type == KeyEventType.KeyDown && !processSettingsPageVisible) {
|
||||
val keys = navigationKeys(s)
|
||||
val at = keys.indexOf(railSelectionNow.value)
|
||||
keys.getOrNull(at + step)?.let { key ->
|
||||
PageSwipe.direction = step
|
||||
onRailSelect(key)
|
||||
}
|
||||
}
|
||||
true
|
||||
} else Modifier),
|
||||
navigation = {
|
||||
if (bottomNavigation) BottomBar(s, railSelection, onRailSelect, onRailFocus, a, railFocus)
|
||||
if (s.dualScreen) Unit
|
||||
else if (bottomNavigation) BottomBar(s, railSelection, onRailSelect, onRailFocus, a, railFocus)
|
||||
else SideRail(s, railSelection, onRailSelect, onRailFocus, a, railFocus.fillMaxHeight())
|
||||
},
|
||||
) {
|
||||
|
||||
@@ -421,6 +421,23 @@ internal fun SetupPanel(
|
||||
if (s.launcherFullscreen) stringResource(R.string.setup_fullscreen_on) else stringResource(R.string.setup_fullscreen_off),
|
||||
s.launcherFullscreen,
|
||||
) { a.onLauncherFullscreen(it) }
|
||||
if (s.dualScreenDevice) {
|
||||
ChoiceRow(
|
||||
host, "dual-screen", stringResource(R.string.setup_dual_screen), stringResource(R.string.setup_dual_screen_hint),
|
||||
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_OFF to stringResource(R.string.setup_dual_screen_off),
|
||||
),
|
||||
s.dualScreenMode, onPick = a.onDualScreenMode,
|
||||
)
|
||||
}
|
||||
if (s.dualScreenDevice && s.dualScreenMode != com.droiddeck.launcher.input.DualScreen.MODE_OFF) {
|
||||
ToggleRow(host, "dual-screen-menu", stringResource(R.string.setup_dual_screen_menu),
|
||||
stringResource(R.string.setup_dual_screen_menu_hint), s.dualScreenLauncher) { a.onDualScreenLauncher(it) }
|
||||
ToggleRow(host, "dual-screen-controls", stringResource(R.string.setup_dual_screen_controls),
|
||||
stringResource(R.string.setup_dual_screen_controls_hint), s.dualScreenControls) { a.onDualScreenControls(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
val art: @Composable () -> Unit = {
|
||||
|
||||
@@ -31,11 +31,11 @@ internal fun LauncherLayout(
|
||||
}) { children, constraints ->
|
||||
val width = constraints.maxWidth
|
||||
val height = constraints.maxHeight
|
||||
val line = 1.dp.roundToPx()
|
||||
val nav = children[2].measure(Constraints(
|
||||
minWidth = if (bottomNavigation) width else 0, maxWidth = width,
|
||||
minHeight = if (bottomNavigation) 0 else height, maxHeight = height,
|
||||
))
|
||||
val line = if ((if (bottomNavigation) nav.height else nav.width) == 0) 0 else 1.dp.roundToPx()
|
||||
val contentWidth = if (bottomNavigation) width else (width - nav.width - line).coerceAtLeast(0)
|
||||
val contentHeight = if (bottomNavigation) (height - nav.height - line).coerceAtLeast(0) else height
|
||||
val pane = children[0].measure(Constraints.fixed(contentWidth, contentHeight))
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
@@ -15,6 +16,7 @@ import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowManager
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Button
|
||||
@@ -22,6 +24,10 @@ import android.widget.FrameLayout
|
||||
import android.widget.HorizontalScrollView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.activity.setViewTreeOnBackPressedDispatcherOwner
|
||||
import androidx.lifecycle.setViewTreeLifecycleOwner
|
||||
import androidx.lifecycle.setViewTreeViewModelStoreOwner
|
||||
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
|
||||
import com.droiddeck.launcher.input.KeyboardHost
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.input.PointerGestures
|
||||
@@ -47,7 +53,14 @@ class SecondScreenPresentation(
|
||||
private val onQam: () -> Unit,
|
||||
private val onClose: () -> Unit,
|
||||
private val pad: PadBridge? = null,
|
||||
private val onKeyboardClosed: () -> Unit = {},
|
||||
private val onMenu: (() -> Unit)? = null,
|
||||
private val menu: (@androidx.compose.runtime.Composable () -> Unit)? = null,
|
||||
) : Presentation(sessionActivity, display) {
|
||||
private val frame = FrameLayout(context)
|
||||
private var menuView: androidx.compose.ui.platform.ComposeView? = null
|
||||
var menuShown = false
|
||||
private set
|
||||
private val root = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
setBackgroundColor(Color.rgb(15, 18, 22))
|
||||
@@ -55,6 +68,10 @@ class SecondScreenPresentation(
|
||||
}
|
||||
private var currentMode = SecondScreenMode.NONE
|
||||
private var keyboardHost: KeyboardHost? = null
|
||||
private var keyboardButton: TextView? = null
|
||||
private var keyboardPending = false
|
||||
private var imeSeen = false
|
||||
private var fieldKeyboard = false
|
||||
private var terminalSession: TerminalSession? = null
|
||||
private var terminalView: TerminalView? = null
|
||||
private var terminalPid = -1
|
||||
@@ -73,18 +90,97 @@ class SecondScreenPresentation(
|
||||
created = true
|
||||
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
|
||||
setContentView(root)
|
||||
frame.addView(root, FrameLayout.LayoutParams(-1, -1))
|
||||
setContentView(frame)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
root.setOnApplyWindowInsetsListener { view, insets ->
|
||||
if (insets.isVisible(WindowInsets.Type.ime())) imeSeen = true
|
||||
else if (imeSeen) keyboardClosed()
|
||||
view.onApplyWindowInsets(insets)
|
||||
}
|
||||
}
|
||||
applyImmersiveMode()
|
||||
renderMode()
|
||||
}
|
||||
|
||||
fun requestKeyboard(forField: Boolean = false) {
|
||||
if (!showsKeyboard || keyboardHost == null) return
|
||||
if (forField) fieldKeyboard = true
|
||||
keyboardPending = true
|
||||
if (window?.decorView?.hasWindowFocus() == true) showPendingKeyboard()
|
||||
}
|
||||
|
||||
private fun showPendingKeyboard() {
|
||||
keyboardPending = false
|
||||
keyboardButton?.text = context.getString(R.string.second_hide_keyboard)
|
||||
for (delay in longArrayOf(150L, 450L)) root.postDelayed({
|
||||
val host = keyboardHost
|
||||
if (host != null && !imeSeen && showsKeyboard) host.show()
|
||||
}, delay)
|
||||
}
|
||||
|
||||
val fieldKeyboardOpen: Boolean get() = fieldKeyboard
|
||||
|
||||
fun closeFieldKeyboard() {
|
||||
if (!fieldKeyboard) return
|
||||
keyboardPending = false
|
||||
keyboardClosed()
|
||||
}
|
||||
|
||||
private fun keyboardClosed() {
|
||||
fieldKeyboard = false
|
||||
imeSeen = false
|
||||
keyboardHost?.takeIf { it.shown }?.hide()
|
||||
keyboardButton?.text = context.getString(R.string.second_show_keyboard)
|
||||
onKeyboardClosed()
|
||||
}
|
||||
|
||||
fun showMode(mode: SecondScreenMode) {
|
||||
if (currentMode == mode && isShowing) return
|
||||
currentMode = mode
|
||||
if (created) renderMode()
|
||||
}
|
||||
|
||||
val showsKeyboard: Boolean get() = isShowing && !menuShown && currentMode == SecondScreenMode.KEYBOARD_TRACKPAD
|
||||
|
||||
val showsControls: Boolean get() = isShowing && currentMode != SecondScreenMode.NONE
|
||||
|
||||
fun showMenu(on: Boolean) {
|
||||
if (on == menuShown) return
|
||||
val content = menu ?: return
|
||||
menuShown = on
|
||||
if (on) {
|
||||
keyboardHost?.takeIf { it.shown }?.hide()
|
||||
window?.decorView?.let { decor ->
|
||||
decor.setViewTreeLifecycleOwner(sessionActivity)
|
||||
decor.setViewTreeViewModelStoreOwner(sessionActivity)
|
||||
decor.setViewTreeSavedStateRegistryOwner(sessionActivity)
|
||||
decor.setViewTreeOnBackPressedDispatcherOwner(sessionActivity)
|
||||
}
|
||||
val view = menuView ?: androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
defaultFocusHighlightEnabled = false
|
||||
setContent { content() }
|
||||
frame.addView(this, FrameLayout.LayoutParams(-1, -1))
|
||||
menuView = this
|
||||
}
|
||||
view.visibility = View.VISIBLE
|
||||
root.visibility = View.INVISIBLE
|
||||
view.requestFocus()
|
||||
} else {
|
||||
menuView?.let { frame.removeView(it); it.disposeComposition() }
|
||||
menuView = null
|
||||
root.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
fun focusMenu(): Boolean = menuView?.requestFocus() == true
|
||||
|
||||
fun dispatchMenuKey(event: KeyEvent): Boolean = menuView?.dispatchKeyEvent(event) == true
|
||||
|
||||
fun closeControls() {
|
||||
showMenu(false)
|
||||
closeTerminal()
|
||||
keyboardHost?.hide()
|
||||
keyboardHost = null
|
||||
@@ -92,23 +188,31 @@ class SecondScreenPresentation(
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (currentMode == SecondScreenMode.KEYBOARD_TRACKPAD) {
|
||||
if (sessionActivity.dispatchKeyEvent(event)) return true
|
||||
}
|
||||
val forward = menuShown || currentMode != SecondScreenMode.TERMINAL || PadBridge.isControllerKeyEvent(event)
|
||||
if (forward && sessionActivity.dispatchKeyEvent(event)) return true
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
if (PadBridge.isControllerMotionEvent(event) && sessionActivity.dispatchGenericMotionEvent(event)) return true
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus) {
|
||||
applyImmersiveMode()
|
||||
sessionActivity.refreshClipboard()
|
||||
if (keyboardPending) showPendingKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderMode() {
|
||||
fieldKeyboard = false
|
||||
keyboardHost?.hide()
|
||||
keyboardHost = null
|
||||
keyboardButton = null
|
||||
keyboardPending = false
|
||||
closeTerminal()
|
||||
root.removeAllViews()
|
||||
val mode = if (currentMode == SecondScreenMode.DECK_CONTROLS && !SessionState.deckPad) SecondScreenMode.NONE
|
||||
@@ -118,7 +222,7 @@ class SecondScreenPresentation(
|
||||
when (mode) {
|
||||
SecondScreenMode.KEYBOARD_TRACKPAD -> renderKeyboardAndTrackpad()
|
||||
SecondScreenMode.TERMINAL -> renderTerminal()
|
||||
SecondScreenMode.DECK_CONTROLS -> root.addView(DeckControlsPanel(context, onClose, onSteamMenu, onQam, pad), weightParams())
|
||||
SecondScreenMode.DECK_CONTROLS -> root.addView(DeckControlsPanel(context, onClose, onSteamMenu, onQam, pad, onMenu = onMenu), weightParams())
|
||||
SecondScreenMode.NONE -> Unit
|
||||
}
|
||||
}
|
||||
@@ -129,49 +233,48 @@ class SecondScreenPresentation(
|
||||
val controls = LinearLayout(context).apply {
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
setPadding(dp(12), dp(8), dp(12), dp(8))
|
||||
setBackgroundColor(0xE6191E24.toInt())
|
||||
setPadding(dp(12), dp(10), dp(12), dp(6))
|
||||
setBackgroundColor(Color.BLACK)
|
||||
}
|
||||
controls.addView(Button(context).apply {
|
||||
text = "×"
|
||||
contentDescription = context.getString(R.string.deck_close)
|
||||
minWidth = dp(48)
|
||||
setOnClickListener { onClose() }
|
||||
})
|
||||
fun gap() = View(context).apply { layoutParams = LinearLayout.LayoutParams(dp(8), 1) }
|
||||
controls.addView(DeckControlsPanel.roundButton(context, "×", context.getString(R.string.deck_close), onClose))
|
||||
controls.addView(TextView(context).apply {
|
||||
text = context.getString(R.string.second_trackpad)
|
||||
textSize = 14f
|
||||
setTextColor(Color.WHITE)
|
||||
typeface = android.graphics.Typeface.create(android.graphics.Typeface.DEFAULT, android.graphics.Typeface.BOLD)
|
||||
setTextColor(Color.rgb(0x7A, 0x80, 0x8A))
|
||||
setPadding(dp(14), 0, dp(8), 0)
|
||||
isSingleLine = true
|
||||
}, LinearLayout.LayoutParams(0, -2, 1f))
|
||||
val keyboardButton = Button(context).apply {
|
||||
text = context.getString(R.string.second_show_keyboard)
|
||||
setOnClickListener {
|
||||
val host = keyboardHost ?: return@setOnClickListener
|
||||
if (host.shown) {
|
||||
host.hide()
|
||||
text = context.getString(R.string.second_show_keyboard)
|
||||
} else {
|
||||
host.show()
|
||||
text = context.getString(R.string.second_hide_keyboard)
|
||||
lateinit var keyboardButton: TextView
|
||||
keyboardButton = DeckControlsPanel.roundButton(context, context.getString(R.string.second_show_keyboard),
|
||||
context.getString(R.string.second_show_keyboard), {
|
||||
val host = keyboardHost
|
||||
if (host != null) {
|
||||
host.toggle()
|
||||
keyboardButton.text = context.getString(if (host.shown) R.string.second_hide_keyboard else R.string.second_show_keyboard)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, wide = true)
|
||||
controls.addView(keyboardButton)
|
||||
this.keyboardButton = keyboardButton
|
||||
onMenu?.let {
|
||||
controls.addView(gap())
|
||||
controls.addView(DeckControlsPanel.menuButton(context, it))
|
||||
}
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) {
|
||||
controls.addView(Button(context).apply {
|
||||
text = "STEAM"
|
||||
contentDescription = context.getString(R.string.deck_open_steam_menu)
|
||||
setOnClickListener { onSteamMenu() }
|
||||
})
|
||||
controls.addView(Button(context).apply {
|
||||
text = "…"
|
||||
contentDescription = context.getString(R.string.drawer_open_qam)
|
||||
setOnClickListener { onQam() }
|
||||
})
|
||||
controls.addView(gap())
|
||||
controls.addView(DeckControlsPanel.roundButton(context, "STEAM", context.getString(R.string.deck_open_steam_menu), onSteamMenu, wide = true))
|
||||
controls.addView(gap())
|
||||
controls.addView(DeckControlsPanel.roundButton(context, "•••", context.getString(R.string.drawer_open_qam), onQam, wide = true))
|
||||
}
|
||||
panel.addView(controls, FrameLayout.LayoutParams(-1, -2, Gravity.TOP))
|
||||
root.addView(panel, weightParams())
|
||||
val host = KeyboardHost(context) { sessionActivity.dispatchKeyEvent(it) }
|
||||
val host = KeyboardHost(context) { event ->
|
||||
val handled = sessionActivity.dispatchKeyEvent(event)
|
||||
if (fieldKeyboard && event.action == KeyEvent.ACTION_UP &&
|
||||
(event.keyCode == KeyEvent.KEYCODE_ENTER || event.keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER)) root.post { closeFieldKeyboard() }
|
||||
handled
|
||||
}
|
||||
keyboardHost = host
|
||||
root.addView(host, ViewGroup.LayoutParams(1, 1))
|
||||
}
|
||||
@@ -329,8 +432,22 @@ class SecondScreenPresentation(
|
||||
if (oldw == 0 || oldh == 0) gestures.place(w / 2f, h / 2f)
|
||||
}
|
||||
|
||||
private val surface = android.graphics.RectF()
|
||||
private val fill = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply { color = Color.rgb(0x0A, 0x0B, 0x0D) }
|
||||
private val edge = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply {
|
||||
style = android.graphics.Paint.Style.STROKE
|
||||
color = Color.rgb(0x26, 0x29, 0x2E)
|
||||
strokeWidth = resources.displayMetrics.density
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
canvas.drawColor(Color.BLACK)
|
||||
val inset = dp(12).toFloat()
|
||||
surface.set(inset, dp(72).toFloat(), width - inset, height - inset)
|
||||
if (surface.height() <= inset) return
|
||||
val radius = dp(20).toFloat()
|
||||
canvas.drawRoundRect(surface, radius, radius, fill)
|
||||
canvas.drawRoundRect(surface, radius, radius, edge)
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean = gestures.onTouch(event)
|
||||
|
||||
@@ -29,6 +29,9 @@ import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material.icons.outlined.Terminal
|
||||
import androidx.compose.material.icons.outlined.Keyboard
|
||||
import androidx.compose.material.icons.outlined.AutoFixHigh
|
||||
import androidx.compose.material.icons.outlined.ExpandMore
|
||||
import androidx.compose.material.icons.outlined.Home
|
||||
@@ -323,7 +326,8 @@ class DrawerActions(
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, controllerActive: Boolean, onPageChange: (SessionDrawerPage) -> Unit, a: DrawerActions) {
|
||||
internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, controllerActive: Boolean, onPageChange: (SessionDrawerPage) -> Unit, a: DrawerActions, docked: Boolean = false,
|
||||
backRequest: Int = 0, onLayerChange: (Boolean) -> Unit = {}) {
|
||||
val pages = sessionDrawerPages(a.secondScreenDisplays.isNotEmpty(), a.glassesPresent)
|
||||
val page = requestedPage.takeIf { it in pages } ?: SessionDrawerPage.CONTROLLER
|
||||
LaunchedEffect(requestedPage, pages) { if (page != requestedPage) onPageChange(page) }
|
||||
@@ -353,6 +357,18 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
if (host.open != null) host.open = null else a.onClose()
|
||||
}
|
||||
BackHandler(enabled = open && confirmStop) { confirmStop = false }
|
||||
val layerOpen = open && (host.open != null || appToChooseDisplay != null || confirmStop)
|
||||
LaunchedEffect(layerOpen) { onLayerChange(layerOpen) }
|
||||
var seenBackRequest by remember { mutableStateOf(backRequest) }
|
||||
LaunchedEffect(backRequest) {
|
||||
if (backRequest == seenBackRequest) return@LaunchedEffect
|
||||
seenBackRequest = backRequest
|
||||
when {
|
||||
confirmStop -> confirmStop = false
|
||||
appToChooseDisplay != null -> appToChooseDisplay = null
|
||||
host.open != null -> host.open = null
|
||||
}
|
||||
}
|
||||
LaunchedEffect(page) { host.open = null; appToChooseDisplay = null }
|
||||
LaunchedEffect(a.selectedGameProfileId) {
|
||||
if (host.open == "fex") host.open = null
|
||||
@@ -383,6 +399,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
val first = when {
|
||||
page == SessionDrawerPage.GLASSES -> "glasses-tab-$glassesTab"
|
||||
page == SessionDrawerPage.SESSION && a.isHomeApp -> "apps"
|
||||
page == SessionDrawerPage.SECOND_SCREEN -> "second-screen:${a.secondScreenMode.id}"
|
||||
else -> page.firstControl
|
||||
}
|
||||
if (turned) focus.forget(page)
|
||||
@@ -394,9 +411,14 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
focus.forget(page)
|
||||
focus.request(first)
|
||||
if (first != page.firstControl) repeat(4) {
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
if (focus.focused == first) return@LaunchedEffect
|
||||
focus.request(page.firstControl)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (open || veil > 0.01f) {
|
||||
if (!docked && (open || veil > 0.01f)) {
|
||||
val closeLabel = stringResource(R.string.common_close)
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
@@ -407,18 +429,18 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
androidx.compose.foundation.layout.BoxWithConstraints(modifier = Modifier.fillMaxSize().exposeTestTags(), contentAlignment = Alignment.CenterEnd) {
|
||||
val short = maxHeight < 440.dp
|
||||
val sheetWidth = minOf(360.dp, maxWidth * 0.92f)
|
||||
val sheetWidth = if (docked) maxWidth else minOf(360.dp, maxWidth * 0.92f)
|
||||
val narrow = sheetWidth < 320.dp
|
||||
AnimatedVisibility(
|
||||
open,
|
||||
enter = slideInHorizontally(Motion.sp(0.8f, Spring.StiffnessLow)) { it } + fadeIn(Motion.tw(220)),
|
||||
exit = slideOutHorizontally(Motion.tw(240)) { it } + fadeOut(Motion.tw(200)),
|
||||
enter = if (docked) fadeIn(Motion.tw(160)) else slideInHorizontally(Motion.sp(0.8f, Spring.StiffnessLow)) { it } + fadeIn(Motion.tw(220)),
|
||||
exit = if (docked) fadeOut(Motion.tw(140)) else slideOutHorizontally(Motion.tw(240)) { it } + fadeOut(Motion.tw(200)),
|
||||
) {
|
||||
FocusGlideHost(Modifier.fillMaxHeight().width(sheetWidth)) { Box(Modifier.fillMaxSize().onGloballyPositioned { sheetCoords = it }) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(pal.background.copy(alpha = 0.97f))
|
||||
.background(if (docked) pal.background else pal.background.copy(alpha = 0.97f))
|
||||
.blockTouches()
|
||||
.focusGroup()
|
||||
.controllerBack {
|
||||
@@ -431,6 +453,13 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 44.dp),
|
||||
) {
|
||||
if (docked) {
|
||||
SteamActionPill(
|
||||
stringResource(R.string.common_close), Icons.Outlined.Close, focus.track(page, "close"),
|
||||
) { host.open = null; a.onClose() }
|
||||
Spacer(Modifier.width(4.dp))
|
||||
BottomScreenModes(a, focus.track(page, "bottom-modes")) { host.open = null }
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
SteamActionPill(
|
||||
stringResource(R.string.stores_dl_pause), Icons.Outlined.Pause, focus.track(page, "pause"),
|
||||
@@ -817,6 +846,52 @@ private fun StopSessionButton(modifier: Modifier = Modifier, onClick: () -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BottomScreenModes(a: DrawerActions, modifier: Modifier, onPick: () -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val modes = buildList {
|
||||
if (com.droiddeck.launcher.session.SessionState.deckPad) add(SecondScreenMode.DECK_CONTROLS to Icons.Outlined.SportsEsports)
|
||||
add(SecondScreenMode.KEYBOARD_TRACKPAD to Icons.Outlined.Keyboard)
|
||||
add(SecondScreenMode.TERMINAL to Icons.Outlined.Terminal)
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
||||
modifier = modifier.focusGroup().clip(RoundedCornerShape(26.dp)).border(1.dp, pal.line, RoundedCornerShape(26.dp)).padding(4.dp),
|
||||
) {
|
||||
modes.forEach { (mode, icon) ->
|
||||
val selected = a.secondScreenMode == mode
|
||||
val source = remember { MutableInteractionSource() }
|
||||
val hot = source.collectIsFocusedAsState().value || source.collectIsHoveredAsState().value
|
||||
val shape = RoundedCornerShape(20.dp)
|
||||
val pick = { onPick(); a.onSecondScreenMode(mode) }
|
||||
val label = stringResource(mode.label)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.size(width = 52.dp, height = 40.dp).semantics { contentDescription = label }
|
||||
.clip(shape)
|
||||
.background(when {
|
||||
selected -> pal.signal
|
||||
hot -> pal.signal.copy(alpha = 0.14f)
|
||||
else -> Color.Transparent
|
||||
})
|
||||
.glideBorder(hot, shape, pal.signal)
|
||||
.hoverable(source)
|
||||
.selectable(selected, interactionSource = source, indication = LocalIndication.current, role = Role.Tab, onClick = pick)
|
||||
.controllerConfirm(onClick = pick),
|
||||
) {
|
||||
Icon(icon, contentDescription = null, modifier = Modifier.size(22.dp),
|
||||
tint = when {
|
||||
selected -> colors.background
|
||||
hot -> pal.signal
|
||||
else -> colors.onBackground
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SteamActionPill(
|
||||
description: String, icon: androidx.compose.ui.graphics.vector.ImageVector, modifier: Modifier,
|
||||
@@ -1648,6 +1723,13 @@ private fun StopConfirm(
|
||||
content = null
|
||||
}
|
||||
}
|
||||
LaunchedEffect(open, controllerActive) {
|
||||
if (!open || !controllerActive || stopFocused || cancelFocused) return@LaunchedEffect
|
||||
delay(Motion.ms(300).toLong())
|
||||
withFrameNanos { }
|
||||
if (stopFocused || cancelFocused) return@LaunchedEffect
|
||||
runCatching { cancelFocus.requestFocus() }
|
||||
}
|
||||
val p = pill ?: return
|
||||
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.ActivityManager
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
|
||||
object SessionTyping {
|
||||
private var activity: SessionTypingActivity? = null
|
||||
private var launching = false
|
||||
|
||||
fun focusDisplay(context: Context, displayId: Int) {
|
||||
if (activity != null || launching) return
|
||||
launching = true
|
||||
val intent = Intent(context, SessionTypingActivity::class.java)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
runCatching {
|
||||
context.startActivity(intent, ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle())
|
||||
}.onFailure { launching = false }
|
||||
}
|
||||
|
||||
fun returnFocus(context: Context, task: Int) {
|
||||
close()
|
||||
if (task < 0) return
|
||||
runCatching { (context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).moveTaskToFront(task, 0) }
|
||||
}
|
||||
|
||||
fun close() {
|
||||
launching = false
|
||||
activity?.finish()
|
||||
activity = null
|
||||
}
|
||||
|
||||
internal fun attach(host: SessionTypingActivity): Boolean {
|
||||
if (!launching) return false
|
||||
launching = false
|
||||
activity = host
|
||||
return true
|
||||
}
|
||||
|
||||
internal fun detach(host: SessionTypingActivity) {
|
||||
if (activity === host) activity = null
|
||||
}
|
||||
}
|
||||
|
||||
class SessionTypingActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (!SessionTyping.attach(this)) finish()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (!isFinishing) finish()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
SessionTyping.detach(this)
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ internal fun IntegrationSuggestion(state: SteamIntegration.State, onOpen: () ->
|
||||
}
|
||||
val closeSrc = remember { MutableInteractionSource() }
|
||||
val closeHot = rememberHot(closeSrc)
|
||||
val later = stringResource(R.string.integration_later)
|
||||
val later = stringResource(R.string.common_close)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = Modifier.padding(end = 4.dp).size(32.dp).clip(CircleShape)
|
||||
|
||||
@@ -253,13 +253,17 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
|
||||
val ids = tabs.filter { it.shown }.map { it.store.id }
|
||||
if (ids.isEmpty()) return
|
||||
val at = ids.indexOf(chip)
|
||||
pickChip(ids[if (at < 0) (if (step > 0) 0 else ids.size - 1) else (at + step + ids.size) % ids.size])
|
||||
val id = ids[if (at < 0) (if (step > 0) 0 else ids.size - 1) else (at + step + ids.size) % ids.size]
|
||||
chip = id; openGame = null; query = ""
|
||||
move("item:storechip:$id")
|
||||
}
|
||||
fun openModes(st: Store) {
|
||||
if (chip != st.id) pickChip(st.id) else move("first")
|
||||
}
|
||||
BackHandler(enabled = openGame != null) { closeGame() }
|
||||
BackHandler(enabled = arranging) { arranging = false }
|
||||
var contentFocused by remember { mutableStateOf(false) }
|
||||
BackHandler(enabled = contentFocused && openGame == null && !arranging) { move("item:storechip:$chip") }
|
||||
LaunchedEffect(arranging) {
|
||||
val focus = ff ?: return@LaunchedEffect
|
||||
if (!arranging || inputMode.inputMode != androidx.compose.ui.input.InputMode.Keyboard) return@LaunchedEffect
|
||||
@@ -348,7 +352,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
|
||||
else scroll.value > 0
|
||||
},
|
||||
onDetailFocus = { detailFocused = it },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f).onSizeChanged { viewportH = with(density) { it.height.toDp() } },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f).onFocusChanged { contentFocused = it.hasFocus }.onSizeChanged { viewportH = with(density) { it.height.toDp() } },
|
||||
bleedHorizontal = padH,
|
||||
wrap = { key, content -> StoreTheme(Store.byId(key.substringBefore(':')) ?: store) { content() } },
|
||||
grid = {
|
||||
|
||||
@@ -28,6 +28,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
@@ -40,10 +41,13 @@ import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.ImeOptions
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.droiddeck.launcher.core.PhantomProcessLimit
|
||||
@@ -373,6 +377,31 @@ internal fun AdbTextField(
|
||||
val shape = RoundedCornerShape(8.dp)
|
||||
val inputHeight = if (compact) 44.dp else 52.dp
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val bottomTyping = LocalBottomTyping.current
|
||||
val bottomTypingLatest = rememberUpdatedState(bottomTyping)
|
||||
val typingRequest = remember { arrayOfNulls<TypingRequest>(1) }
|
||||
|
||||
fun typeOnBottom(editText: EditText): Boolean {
|
||||
if (!bottomTypingLatest.value || !DualScreenPanel.attached) return false
|
||||
val text = editText.text.toString()
|
||||
val request = TypingRequest(
|
||||
TextFieldValue(text, TextRange(editText.selectionStart.coerceIn(0, text.length), editText.selectionEnd.coerceIn(0, text.length))),
|
||||
ImeOptions(singleLine = true, keyboardType = keyboardType, imeAction = imeAction),
|
||||
{ next ->
|
||||
if (editText.text.toString() != next.text) editText.setText(next.text)
|
||||
editText.setSelection(next.selection.start.coerceIn(0, next.text.length), next.selection.end.coerceIn(0, next.text.length))
|
||||
},
|
||||
{ action -> editText.onEditorAction(imeActionFlag(action)) },
|
||||
{ editText.post { editText.clearFocus() } },
|
||||
)
|
||||
typingRequest[0] = request
|
||||
DualScreenPanel.startTyping(request)
|
||||
return true
|
||||
}
|
||||
|
||||
DisposableEffect(Unit) {
|
||||
onDispose { typingRequest[0]?.let { DualScreenPanel.stopTyping(it) } }
|
||||
}
|
||||
|
||||
Column(modifier = modifier.fillMaxWidth()) {
|
||||
if (showLabel) Text(
|
||||
@@ -424,8 +453,12 @@ internal fun AdbTextField(
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
showSoftInputOnFocus = !bottomTyping
|
||||
setOnClickListener { if (hasFocus() && !typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
setOnFocusChangeListener { _, hasFocus ->
|
||||
focused = hasFocus
|
||||
if (hasFocus) { if (!typeOnBottom(this) && bottomTypingLatest.value) showKeyboardHere(this) }
|
||||
else typingRequest[0]?.let { DualScreenPanel.stopTyping(it) }
|
||||
onFocusChangeLatest.value(hasFocus)
|
||||
}
|
||||
addTextChangedListener(object : TextWatcher {
|
||||
@@ -438,11 +471,12 @@ internal fun AdbTextField(
|
||||
}
|
||||
},
|
||||
update = { editText ->
|
||||
editText.showSoftInputOnFocus = !bottomTyping
|
||||
if (focusOnShow && !focusAsked[0]) {
|
||||
focusAsked[0] = true
|
||||
editText.post {
|
||||
editText.requestFocus()
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
if (!bottomTypingLatest.value) (editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
@@ -548,6 +582,11 @@ private fun parseAdbAddress(value: String): AdbEndpoint? {
|
||||
private fun formatAddressHost(host: String): String = if (':' in host) "[$host]" else host
|
||||
private fun formatAdbAddress(host: String, port: Int): String = "${formatAddressHost(host)}:$port"
|
||||
|
||||
private fun showKeyboardHere(editText: EditText) {
|
||||
(editText.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
|
||||
?.showSoftInput(editText, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
private fun imeActionFlag(action: ImeAction): Int = when (action) {
|
||||
ImeAction.Next -> EditorInfo.IME_ACTION_NEXT
|
||||
ImeAction.Done -> EditorInfo.IME_ACTION_DONE
|
||||
|
||||
Reference in new issue
Block a user