mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: consistent bottom screen bar and menu-first navigation in sessions (#2084)
This commit is contained in:
1 parent
940efdab3a
commit
eed9edaa1c
18 files changed
+852
-575
No files matched your search
@@ -3,6 +3,7 @@ package com.droiddeck.launcher
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import android.hardware.input.InputManager
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.content.Intent
|
||||
@@ -342,13 +343,21 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private var drawerOpenState by mutableStateOf(false)
|
||||
private var typingReturnMode: SecondScreenMode? = null
|
||||
private var drawerDocked by mutableStateOf(false)
|
||||
private var drawerPinned 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
|
||||
if (value == drawerOpenState) {
|
||||
if (!value && drawerPinned) {
|
||||
drawerPinned = false
|
||||
if (drawerDocked) closeDockedMenu()
|
||||
}
|
||||
return
|
||||
}
|
||||
drawerLayerOpen = false
|
||||
drawerPinned = false
|
||||
if (value) drawerDocked = dockDrawer() && openDockedMenu()
|
||||
drawerOpenState = value
|
||||
if (!value && drawerDocked) closeDockedMenu()
|
||||
@@ -1168,7 +1177,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
|
||||
@androidx.compose.runtime.Composable
|
||||
private fun SessionMenu(docked: Boolean) {
|
||||
SessionDrawer(drawerOpen, drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, docked = docked,
|
||||
SessionDrawer(drawerOpen || (docked && drawerPinned), drawerPage, drawerControllerActive, onPageChange = { drawerPage = it }, docked = docked,
|
||||
backRequest = drawerBackRequests, onLayerChange = { drawerLayerOpen = it }, a = DrawerActions(
|
||||
steam = SessionState.mode == SessionService.MODE_STEAM,
|
||||
direct = noSteamSession(),
|
||||
@@ -1205,6 +1214,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
touchAuto = getString(if (usingTouchpad()) R.string.session_touch_auto_touchpad else R.string.session_touch_auto_direct),
|
||||
fexPreset = fexPreset,
|
||||
secondScreenMode = secondScreenMode,
|
||||
secondScreenNone = !bottomOutputActive && !dockDrawer(),
|
||||
gameOnBottom = bottomOutputActive,
|
||||
gameSwapAvailable = bottomSwapAvailable,
|
||||
onGameOnBottom = { on -> drawerOpen = false; putGameOnBottom(on) },
|
||||
@@ -1405,6 +1415,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
},
|
||||
onClose = { drawerOpen = false },
|
||||
onDismissScreen = if (docked) ({ selectSecondScreenMode(SecondScreenMode.NONE) }) else null,
|
||||
components = drawerComponents,
|
||||
onComponentsRefresh = {
|
||||
refreshDrawerComponents()
|
||||
@@ -2248,6 +2259,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun cancelTouchGestures() {
|
||||
if (::touchscreenGestures.isInitialized) touchscreenGestures.cancel()
|
||||
if (::touchpad.isInitialized) touchpad.cancel()
|
||||
if (::directTouchHold.isInitialized) directTouchHold.cancel()
|
||||
if (::scrollTouch.isInitialized) scrollTouch.cancel()
|
||||
scrollTouchGesture = false
|
||||
gesturePointerReady = false
|
||||
@@ -3119,6 +3131,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (secondScreenMode != SecondScreenMode.NONE) showSecondScreen(secondScreenMode)
|
||||
}
|
||||
|
||||
private fun closeBottomPanel() {
|
||||
if (dockDrawer()) drawerOpen = true else selectSecondScreenMode(SecondScreenMode.NONE)
|
||||
}
|
||||
|
||||
private fun selectSecondScreenMode(mode: SecondScreenMode) {
|
||||
dualControlsProvisional = false
|
||||
if (mode == SecondScreenMode.NONE) {
|
||||
@@ -3177,23 +3193,27 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
sendWheel = { steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) },
|
||||
onSteamMenu = ::tapSteamButton,
|
||||
onQam = ::tapQam,
|
||||
onClose = { selectSecondScreenMode(SecondScreenMode.NONE) },
|
||||
onClose = ::closeBottomPanel,
|
||||
pad = padBridge,
|
||||
onKeyboardClosed = ::bottomKeyboardClosed,
|
||||
onMenu = if (dockDrawer()) ({ drawerOpen = true }) else null,
|
||||
onMenu = { drawerOpen = true },
|
||||
onMenuTouched = {
|
||||
if (drawerPinned) {
|
||||
drawerPinned = false
|
||||
drawerOpenState = true
|
||||
updateKeyboardRoute()
|
||||
}
|
||||
},
|
||||
menu = {
|
||||
DroidDeckTheme { SessionMenu(docked = true) }
|
||||
},
|
||||
onSwap = if (com.droiddeck.launcher.input.DualScreen.builtIn(target)) ({ putGameOnBottom(true) }) else null,
|
||||
onSwap = if (bottomSwapAvailable && com.droiddeck.launcher.input.DualScreen.builtIn(target)) ({ putGameOnBottom(true) }) else null,
|
||||
dashboard = if (bottomPages().isEmpty()) null else ({
|
||||
DroidDeckTheme {
|
||||
BottomDashboard(
|
||||
bottomPages(), com.droiddeck.launcher.ui.SessionBottomTab.picked(SessionState.sessionId),
|
||||
gameStarts = gameStarts,
|
||||
onPage = { com.droiddeck.launcher.ui.SessionBottomTab.pick(SessionState.sessionId, it) },
|
||||
onClose = { selectSecondScreenMode(SecondScreenMode.NONE) },
|
||||
onMenu = if (dockDrawer()) ({ drawerOpen = true }) else null,
|
||||
onSwap = if (bottomSwapAvailable && com.droiddeck.launcher.input.DualScreen.builtIn(target)) ({ putGameOnBottom(true) }) else null,
|
||||
strip = { pageId ->
|
||||
com.droiddeck.launcher.ui.SessionBottomStrip(pageId) { if (::hud.isInitialized) hud.liveFps else null }
|
||||
},
|
||||
@@ -3346,7 +3366,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (panel == null) {
|
||||
panel = com.droiddeck.launcher.ui.DeckControlsPanel(this, onClose = { chooseUnfoldedControls(false) },
|
||||
onSteamMenu = ::tapSteamButton, onQam = ::tapQam, pad = padBridge,
|
||||
portraitDock = !com.droiddeck.launcher.session.SessionDisplay.foldable(this))
|
||||
portraitDock = !com.droiddeck.launcher.session.SessionDisplay.foldable(this), onMenu = { drawerOpen = true })
|
||||
sessionRoot.addView(panel, sessionRoot.indexOfChild(surfaceView) + 1)
|
||||
unfoldedPanel = panel
|
||||
updateOnScreenControls()
|
||||
@@ -3369,7 +3389,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (!started) return
|
||||
if (secondScreenPresentation?.showsKeyboard != true && dockDrawer()) {
|
||||
val target = com.droiddeck.launcher.input.DualScreen.sessionDisplay(this, displayManager, shownOnDisplayId) ?: return
|
||||
if (drawerOpen) drawerOpen = false
|
||||
if (drawerOpen || drawerPinned) drawerOpen = false
|
||||
typingReturnMode = secondScreenMode
|
||||
selectedSecondScreenDisplay = target.displayId
|
||||
selectSecondScreenMode(SecondScreenMode.KEYBOARD_TRACKPAD)
|
||||
@@ -3394,6 +3414,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
}
|
||||
|
||||
private fun dropDockedDrawer() {
|
||||
drawerPinned = false
|
||||
if (!drawerDocked) return
|
||||
drawerDocked = false
|
||||
drawerLayerOpen = false
|
||||
@@ -3546,7 +3567,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
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
|
||||
drawerLayerOpen = false
|
||||
drawerOpenState = false
|
||||
drawerPinned = true
|
||||
updateKeyboardRoute()
|
||||
dismissTouch = true
|
||||
}
|
||||
if (dismissTouch) {
|
||||
@@ -4524,31 +4548,67 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun SwappedTopPanel() {
|
||||
val pages = bottomPages()
|
||||
val swapBack = { putGameOnBottom(false) }
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM
|
||||
val openMenu = { drawerOpen = true }
|
||||
fun bar(title: String?, extras: List<com.droiddeck.launcher.ui.BarExtra> = emptyList()) = com.droiddeck.launcher.ui.BottomBarModel(
|
||||
title, openMenu, openMenu, if (steam) ({ tapSteamButton() }) else null, if (steam) ({ tapQam() }) else null,
|
||||
extras + com.droiddeck.launcher.ui.BarExtra(getString(R.string.swap_screens), icon = R.drawable.ic_bottom_swap, onClick = swapBack),
|
||||
)
|
||||
val keyboardExtra = com.droiddeck.launcher.ui.BarExtra(getString(R.string.second_show_keyboard), icon = R.drawable.ic_bottom_keyboard) {
|
||||
keyboard?.toggle()
|
||||
}
|
||||
androidx.compose.foundation.layout.Box(
|
||||
Modifier.fillMaxSize().background(androidx.compose.material3.MaterialTheme.colorScheme.background)
|
||||
Modifier.fillMaxSize().background(androidx.compose.ui.graphics.Color.Black)
|
||||
.pointerInput(Unit) { awaitPointerEventScope { while (true) awaitPointerEvent() } },
|
||||
) {
|
||||
if (secondScreenMode == SecondScreenMode.DESKTOP && com.droiddeck.launcher.session.BottomDesktop.available()) {
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context ->
|
||||
com.droiddeck.launcher.ui.BottomDesktopPanel(context, null, { drawerOpen = true },
|
||||
(({ tapSteamButton() }) to ({ tapQam() })).takeIf { SessionState.mode == SessionService.MODE_STEAM }, swapBack,
|
||||
fullResolution = true)
|
||||
when {
|
||||
secondScreenMode == SecondScreenMode.DESKTOP && com.droiddeck.launcher.session.BottomDesktop.available() ->
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context ->
|
||||
com.droiddeck.launcher.ui.BottomDesktopPanel(context, openMenu, openMenu,
|
||||
(({ tapSteamButton() }) to ({ tapQam() })).takeIf { steam }, swapBack, fullResolution = true)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
secondScreenMode == SecondScreenMode.DECK_CONTROLS && SessionState.deckPad ->
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context ->
|
||||
com.droiddeck.launcher.ui.DeckControlsPanel(context, onClose = openMenu, onSteamMenu = ::tapSteamButton,
|
||||
onQam = ::tapQam, pad = padBridge, onMenu = openMenu, onSwap = swapBack)
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
secondScreenMode == SecondScreenMode.KEYBOARD_TRACKPAD -> androidx.compose.foundation.layout.Column(Modifier.fillMaxSize()) {
|
||||
com.droiddeck.launcher.ui.BottomScreenBar(bar(getString(SecondScreenMode.KEYBOARD_TRACKPAD.label), listOf(keyboardExtra)))
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context ->
|
||||
com.droiddeck.launcher.ui.SessionTrackpadView(context, ::moveSecondScreenPointer,
|
||||
{ button, pressed -> WaylandCompositor.nativeSendSceneInput(3, button, if (pressed) 1 else 0) },
|
||||
{ steps -> WaylandCompositor.nativeSendSceneInput(4, steps, 0) })
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
)
|
||||
}
|
||||
secondScreenMode == SecondScreenMode.TERMINAL -> androidx.compose.foundation.layout.Column(Modifier.fillMaxSize()) {
|
||||
var terminal by androidx.compose.runtime.remember { androidx.compose.runtime.mutableStateOf<com.droiddeck.launcher.ui.SessionTerminalPanel?>(null) }
|
||||
com.droiddeck.launcher.ui.BottomScreenBar(bar(getString(SecondScreenMode.TERMINAL.label), listOf(
|
||||
com.droiddeck.launcher.ui.BarExtra(getString(R.string.drawer_keyboard), icon = R.drawable.ic_bottom_keyboard) { terminal?.showKeyboard() },
|
||||
)))
|
||||
androidx.compose.ui.viewinterop.AndroidView(
|
||||
factory = { context -> com.droiddeck.launcher.ui.SessionTerminalPanel(context).also { terminal = it } },
|
||||
modifier = Modifier.fillMaxWidth().weight(1f),
|
||||
)
|
||||
}
|
||||
pages.isEmpty() -> com.droiddeck.launcher.ui.BottomScreenBar(bar(null))
|
||||
else -> BottomDashboard(
|
||||
pages, com.droiddeck.launcher.ui.SessionBottomTab.picked(SessionState.sessionId),
|
||||
gameStarts = gameStarts,
|
||||
onPage = { com.droiddeck.launcher.ui.SessionBottomTab.pick(SessionState.sessionId, it) },
|
||||
bar = bar(getString(R.string.second_mode_dashboard)),
|
||||
strip = { pageId ->
|
||||
com.droiddeck.launcher.ui.SessionBottomStrip(pageId) { if (::hud.isInitialized) hud.liveFps else null }
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
)
|
||||
} else if (pages.isNotEmpty()) BottomDashboard(
|
||||
pages, com.droiddeck.launcher.ui.SessionBottomTab.picked(SessionState.sessionId),
|
||||
gameStarts = gameStarts,
|
||||
onPage = { com.droiddeck.launcher.ui.SessionBottomTab.pick(SessionState.sessionId, it) },
|
||||
onClose = null,
|
||||
onMenu = { drawerOpen = true },
|
||||
onSwap = swapBack,
|
||||
strip = { pageId ->
|
||||
com.droiddeck.launcher.ui.SessionBottomStrip(pageId) { if (::hud.isInitialized) hud.liveFps else null }
|
||||
},
|
||||
) else androidx.compose.material3.Button(onClick = swapBack, modifier = Modifier.align(androidx.compose.ui.Alignment.Center)) {
|
||||
androidx.compose.material3.Text(getString(R.string.swap_screens))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ enum class SecondScreenMode(val id: String, @StringRes val label: Int) {
|
||||
}?.let { return it }
|
||||
val picked = entries.any { it != NONE && it.id == remembered }
|
||||
return when {
|
||||
dashboard && !picked -> DASHBOARD
|
||||
deckPad -> DECK_CONTROLS
|
||||
dashboard && !picked -> DASHBOARD
|
||||
else -> KEYBOARD_TRACKPAD
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,23 @@ package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
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.fillMaxHeight
|
||||
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.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material.icons.outlined.Menu
|
||||
import androidx.compose.material.icons.outlined.SwapVert
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -72,24 +70,18 @@ internal object SessionBottomTab {
|
||||
|
||||
internal fun pageForGameStart(ids: List<String>): String? = GAME_PAGE.takeIf { it in ids }
|
||||
|
||||
private const val DEFAULT_PAGE = "chat"
|
||||
private const val DEFAULT_PAGE = "telemetry"
|
||||
private const val GAME_PAGE = "telemetry"
|
||||
|
||||
internal fun bottomTabsWithLabels(widthDp: Float, tabs: Int): Boolean = tabs * TAB_WIDTH + 2 * BAR_BUTTON <= widthDp
|
||||
|
||||
private const val TAB_WIDTH = 132f
|
||||
private const val BAR_BUTTON = 56f
|
||||
private val MIN_TAB = 80.dp
|
||||
|
||||
@Composable
|
||||
fun BottomDashboard(
|
||||
internal fun BottomDashboard(
|
||||
pages: List<BottomPage>,
|
||||
remembered: String?,
|
||||
onPage: (String) -> Unit,
|
||||
onClose: (() -> Unit)?,
|
||||
onMenu: (() -> Unit)?,
|
||||
bar: BottomBarModel? = null,
|
||||
gameStarts: Int = 0,
|
||||
strip: (@Composable (String?) -> Unit)? = null,
|
||||
onSwap: (() -> Unit)? = null,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
var current by remember { mutableStateOf(pickBottomPage(remembered, pages.map { it.id })) }
|
||||
@@ -98,24 +90,25 @@ fun BottomDashboard(
|
||||
if (gameStarts != startsWhenOpened) pageForGameStart(pages.map { it.id })?.let { current = it }
|
||||
}
|
||||
val page = pages.firstOrNull { it.id == current } ?: pages.firstOrNull()
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(colors.background)) {
|
||||
val labels = bottomTabsWithLabels(maxWidth.value, pages.size)
|
||||
Column(Modifier.fillMaxSize().padding(horizontal = 12.dp, vertical = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Row(Modifier.fillMaxWidth().height(48.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
if (onClose != null) BarButton(Icons.Outlined.Close, stringResource(R.string.deck_close), "bottom-close", onClose)
|
||||
Row(Modifier.weight(1f).horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
pages.forEach { p ->
|
||||
PageTab(p, p.id == page?.id, labels) {
|
||||
current = p.id
|
||||
onPage(p.id)
|
||||
}
|
||||
Column(Modifier.fillMaxSize().background(colors.background)) {
|
||||
bar?.let { BottomScreenBar(it) }
|
||||
BoxWithConstraints(Modifier.fillMaxWidth().padding(start = 12.dp, end = 12.dp, bottom = 8.dp).height(56.dp)) {
|
||||
val roomy = pages.isEmpty() || (maxWidth - 6.dp * (pages.size - 1)) / pages.size >= MIN_TAB
|
||||
Row(
|
||||
Modifier.fillMaxSize().then(if (roomy) Modifier else Modifier.horizontalScroll(rememberScrollState())),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
) {
|
||||
pages.forEach { p ->
|
||||
PageTab(p, p.id == page?.id, if (roomy) Modifier.weight(1f) else Modifier.width(MIN_TAB)) {
|
||||
current = p.id
|
||||
onPage(p.id)
|
||||
}
|
||||
}
|
||||
if (onSwap != null) BarButton(Icons.Outlined.SwapVert, stringResource(R.string.swap_screens), "bottom-swap", onSwap)
|
||||
if (onMenu != null) BarButton(Icons.Outlined.Menu, stringResource(R.string.touch_droiddeck_menu), "bottom-menu", onMenu)
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f).fillMaxWidth().padding(horizontal = 12.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
strip?.invoke(page?.id)
|
||||
Box(Modifier.weight(1f).fillMaxWidth()) {
|
||||
Box(Modifier.weight(1f).fillMaxWidth().padding(bottom = 10.dp)) {
|
||||
if (page != null) page.content()
|
||||
else Text(stringResource(R.string.bottom_dashboard_empty), fontSize = 15.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.align(Alignment.Center))
|
||||
@@ -125,35 +118,24 @@ fun BottomDashboard(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BarButton(icon: ImageVector, label: String, tag: String, onClick: () -> Unit) {
|
||||
val pal = LocalPalette.current
|
||||
Box(
|
||||
Modifier.size(44.dp).clip(RoundedCornerShape(22.dp)).background(pal.surface).border(1.dp, pal.line, RoundedCornerShape(22.dp))
|
||||
.semantics { contentDescription = label }.clickable(role = Role.Button, onClick = onClick).testTag(tag),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = MaterialTheme.colorScheme.onBackground, modifier = Modifier.size(22.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PageTab(page: BottomPage, selected: Boolean, label: Boolean, onClick: () -> Unit) {
|
||||
private fun PageTab(page: BottomPage, selected: Boolean, modifier: Modifier, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val shape = RoundedCornerShape(20.dp)
|
||||
val shape = RoundedCornerShape(14.dp)
|
||||
val name = stringResource(page.label)
|
||||
Row(
|
||||
Modifier.height(44.dp).clip(shape)
|
||||
Column(
|
||||
modifier.fillMaxHeight().clip(shape)
|
||||
.background(if (selected) pal.signal else Color.Transparent)
|
||||
.border(1.dp, if (selected) pal.signal else pal.line, shape)
|
||||
.semantics { contentDescription = name }
|
||||
.clickable(role = Role.Tab, onClick = onClick).testTag("bottom-page-${page.id}")
|
||||
.padding(horizontal = 14.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
.padding(horizontal = 4.dp, vertical = 6.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
val tint = if (selected) colors.background else colors.onBackground
|
||||
val tint = if (selected) pal.onSignal else colors.onBackground
|
||||
Icon(page.icon, contentDescription = null, tint = tint, modifier = Modifier.size(20.dp))
|
||||
if (label || selected) Text(name, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = tint, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(name, fontSize = 11.sp, lineHeight = 13.sp, fontWeight = FontWeight.SemiBold, color = tint, maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis, modifier = Modifier.padding(top = 2.dp))
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.SystemClock
|
||||
import android.graphics.Typeface
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
@@ -20,8 +19,6 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.GuestKeys
|
||||
import com.droiddeck.launcher.input.InputSpace
|
||||
@@ -49,8 +46,7 @@ class BottomDesktopPanel(
|
||||
}
|
||||
private val keyboardHost = KeyboardHost(context) { event -> sendKey(event) }
|
||||
private var directTouch = SessionPrefs.bottomDesktopDirectTouch(context)
|
||||
private lateinit var touchButton: ImageView
|
||||
private lateinit var title: TextView
|
||||
private val touchMode = mutableStateOf(directTouch)
|
||||
private val trackpad = TouchpadGestures(ViewConfiguration.get(context).scaledTouchSlop.toFloat(), TrackpadInput()).apply {
|
||||
desktop = true
|
||||
}
|
||||
@@ -87,45 +83,21 @@ class BottomDesktopPanel(
|
||||
area.addView(surfaceView, 1, FrameLayout.LayoutParams(fullWidth.takeIf { it > 0 } ?: -1, fullHeight.takeIf { it > 0 } ?: -1))
|
||||
}
|
||||
|
||||
private fun bar(onClose: (() -> Unit)?, onMenu: (() -> Unit)?, steamButtons: Pair<() -> Unit, () -> Unit>?, onSwap: (() -> Unit)?): View {
|
||||
val bar = LinearLayout(context).apply {
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
setPadding(dp(8), dp(6), dp(8), dp(6))
|
||||
setBackgroundColor(Color.BLACK)
|
||||
private fun bar(onClose: (() -> Unit)?, onMenu: (() -> Unit)?, steamButtons: Pair<() -> Unit, () -> Unit>?, onSwap: (() -> Unit)?): View =
|
||||
bottomScreenBarView(context) {
|
||||
val touch = touchMode.value
|
||||
BottomBarModel(
|
||||
context.getString(R.string.bottom_desktop_title,
|
||||
context.getString(if (touch) R.string.bottom_desktop_mode_touch else R.string.bottom_desktop_mode_trackpad)),
|
||||
onClose, onMenu, steamButtons?.first, steamButtons?.second,
|
||||
listOfNotNull(
|
||||
BarExtra(context.getString(if (touch) R.string.bottom_desktop_direct_touch else R.string.bottom_desktop_trackpad),
|
||||
icon = if (touch) R.drawable.ic_bottom_touch else R.drawable.ic_bottom_mouse) { setDirectTouch(!directTouch) },
|
||||
BarExtra(context.getString(R.string.second_show_keyboard), icon = R.drawable.ic_bottom_keyboard) { keyboardHost.toggle() },
|
||||
onSwap?.let { BarExtra(context.getString(R.string.swap_screens), icon = R.drawable.ic_bottom_swap, onClick = it) },
|
||||
),
|
||||
)
|
||||
}
|
||||
fun gap() = View(context).apply { layoutParams = LayoutParams(dp(6), 1) }
|
||||
onClose?.let { bar.addView(DeckControlsPanel.roundButton(context, "×", context.getString(R.string.deck_close), it)) }
|
||||
title = TextView(context).apply {
|
||||
textSize = 14f
|
||||
typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
|
||||
setTextColor(Color.rgb(0x7A, 0x80, 0x8A))
|
||||
setPadding(dp(12), 0, dp(6), 0)
|
||||
isSingleLine = true
|
||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
}
|
||||
bar.addView(title, LayoutParams(0, -2, 1f))
|
||||
touchButton = DeckControlsPanel.iconButton(context, R.drawable.ic_bottom_mouse, "") { setDirectTouch(!directTouch) }
|
||||
bar.addView(touchButton)
|
||||
bar.addView(gap())
|
||||
bar.addView(DeckControlsPanel.iconButton(context, R.drawable.ic_bottom_keyboard,
|
||||
context.getString(R.string.second_show_keyboard)) { keyboardHost.toggle() })
|
||||
onSwap?.let {
|
||||
bar.addView(gap())
|
||||
bar.addView(DeckControlsPanel.iconButton(context, R.drawable.ic_bottom_swap, context.getString(R.string.swap_screens), it))
|
||||
}
|
||||
onMenu?.let {
|
||||
bar.addView(gap())
|
||||
bar.addView(DeckControlsPanel.menuButton(context, it))
|
||||
}
|
||||
steamButtons?.let { (steam, qam) ->
|
||||
bar.addView(gap())
|
||||
bar.addView(DeckControlsPanel.roundButton(context, "STEAM", context.getString(R.string.deck_open_steam_menu), steam, wide = true))
|
||||
bar.addView(gap())
|
||||
bar.addView(DeckControlsPanel.roundButton(context, "•••", context.getString(R.string.drawer_open_qam), qam, wide = true))
|
||||
}
|
||||
return bar
|
||||
}
|
||||
|
||||
private fun setDirectTouch(on: Boolean) {
|
||||
trackpad.cancel()
|
||||
@@ -136,11 +108,7 @@ class BottomDesktopPanel(
|
||||
}
|
||||
|
||||
private fun showTouchMode() {
|
||||
touchButton.setImageResource(if (directTouch) R.drawable.ic_bottom_touch else R.drawable.ic_bottom_mouse)
|
||||
touchButton.contentDescription = context.getString(
|
||||
if (directTouch) R.string.bottom_desktop_direct_touch else R.string.bottom_desktop_trackpad)
|
||||
title.text = context.getString(R.string.bottom_desktop_title,
|
||||
context.getString(if (directTouch) R.string.bottom_desktop_mode_touch else R.string.bottom_desktop_mode_trackpad))
|
||||
touchMode.value = directTouch
|
||||
BottomDesktop.showCursor(!directTouch)
|
||||
if (!directTouch && surfaceView.width > 0) {
|
||||
trackpad.bounds = RectF(0f, 0f, surfaceView.width.toFloat(), surfaceView.height.toFloat())
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState
|
||||
import androidx.compose.foundation.interaction.collectIsHoveredAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
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.layout.widthIn
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material.icons.outlined.MoreHoriz
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
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.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
internal class BarExtra(
|
||||
val description: String,
|
||||
val icon: Int? = null,
|
||||
val vector: ImageVector? = null,
|
||||
val active: Boolean = false,
|
||||
val tag: String? = null,
|
||||
val onClick: () -> Unit,
|
||||
)
|
||||
|
||||
internal class BottomBarModel(
|
||||
val title: String?,
|
||||
val onClose: (() -> Unit)?,
|
||||
val onMenu: (() -> Unit)?,
|
||||
val onSteam: (() -> Unit)?,
|
||||
val onQam: (() -> Unit)?,
|
||||
val extras: List<BarExtra> = emptyList(),
|
||||
val menuActive: Boolean = false,
|
||||
)
|
||||
|
||||
@Composable
|
||||
internal fun BottomScreenBar(model: BottomBarModel, modifier: Modifier = Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
BoxWithConstraints(modifier.fillMaxWidth().height(BAR_HEIGHT).blockTouches()) {
|
||||
val buttons = listOfNotNull(model.onClose, model.onMenu, model.onQam).size + model.extras.size
|
||||
val steamWidth = if (model.onSteam != null) STEAM_WIDTH + BAR_GAP else 0.dp
|
||||
val titleWidth = if (model.title != null) MIN_TITLE + BAR_GAP else 0.dp
|
||||
val needed = BAR_PAD * 2 + BUTTON * buttons + BAR_GAP * (buttons - 1).coerceAtLeast(0) + steamWidth + titleWidth
|
||||
val fits = maxWidth >= needed
|
||||
Row(
|
||||
Modifier.fillMaxSize().then(if (fits) Modifier else Modifier.horizontalScroll(rememberScrollState()))
|
||||
.padding(horizontal = BAR_PAD, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(BAR_GAP),
|
||||
) {
|
||||
model.onClose?.let {
|
||||
BarButton(stringResource(R.string.common_close), Modifier.testTag("bottom-bar-close"), vector = Icons.Outlined.Close, onClick = it)
|
||||
}
|
||||
if (model.title != null) Text(
|
||||
model.title, fontSize = 14.sp, fontWeight = FontWeight.Bold, color = colors.onSurfaceVariant,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis,
|
||||
modifier = (if (fits) Modifier.weight(1f) else Modifier).padding(start = 4.dp),
|
||||
) else if (fits) Spacer(Modifier.weight(1f))
|
||||
model.extras.forEach { extra ->
|
||||
BarButton(extra.description, extra.tag?.let { Modifier.testTag(it) } ?: Modifier, icon = extra.icon, vector = extra.vector,
|
||||
active = extra.active, onClick = extra.onClick)
|
||||
}
|
||||
BarActions(model.onMenu, model.menuActive, model.onSteam, model.onQam)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun BarActions(
|
||||
onMenu: (() -> Unit)?,
|
||||
menuActive: Boolean,
|
||||
onSteam: (() -> Unit)?,
|
||||
onQam: (() -> Unit)?,
|
||||
menuModifier: Modifier = Modifier,
|
||||
steamModifier: Modifier = Modifier,
|
||||
qamModifier: Modifier = Modifier,
|
||||
qamInteraction: MutableInteractionSource? = null,
|
||||
onQamConfirm: (() -> Unit)? = null,
|
||||
) {
|
||||
onMenu?.let {
|
||||
BarButton(stringResource(R.string.touch_droiddeck_menu), menuModifier.testTag("bottom-bar-menu"), icon = R.drawable.ic_stat_session,
|
||||
active = menuActive, onClick = it)
|
||||
}
|
||||
onSteam?.let {
|
||||
BarButton(stringResource(R.string.drawer_steam_menu), steamModifier.testTag("bottom-bar-steam"), label = "STEAM", onClick = it)
|
||||
}
|
||||
onQam?.let {
|
||||
BarButton(stringResource(R.string.drawer_open_qam), qamModifier.testTag("bottom-bar-qam"), vector = Icons.Outlined.MoreHoriz,
|
||||
interactionSource = qamInteraction ?: remember { MutableInteractionSource() }, onConfirm = onQamConfirm, onClick = it)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun BarButton(
|
||||
description: String,
|
||||
modifier: Modifier = Modifier,
|
||||
icon: Int? = null,
|
||||
vector: ImageVector? = null,
|
||||
label: String? = null,
|
||||
active: Boolean = false,
|
||||
danger: Boolean = false,
|
||||
shortcut: String? = null,
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
onConfirm: (() -> Unit)? = null,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val hot = interactionSource.collectIsFocusedAsState().value || interactionSource.collectIsHoveredAsState().value
|
||||
val shape = RoundedCornerShape(22.dp)
|
||||
val accent = if (danger) colors.error else pal.signal
|
||||
val tint = when {
|
||||
active -> pal.onSignal
|
||||
hot || danger -> accent
|
||||
else -> colors.onBackground
|
||||
}
|
||||
val fill = when {
|
||||
active -> pal.signal
|
||||
hot -> accent.copy(alpha = 0.14f)
|
||||
else -> Color.Transparent
|
||||
}
|
||||
val sized = if (label != null) Modifier.height(44.dp).widthIn(min = 44.dp) else Modifier.size(44.dp)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier.then(sized).semantics { contentDescription = description }
|
||||
.clip(shape).background(fill)
|
||||
.glideBorder(hot, shape, accent, if (active) pal.signal else if (danger) colors.error.copy(alpha = 0.6f) else pal.line)
|
||||
.hoverable(interactionSource)
|
||||
.clickable(role = Role.Button, interactionSource = interactionSource, indication = LocalIndication.current, onClick = onClick)
|
||||
.controllerConfirm(onClick = onConfirm ?: onClick),
|
||||
) {
|
||||
when {
|
||||
label != null -> Text(label, fontSize = 13.sp, fontWeight = FontWeight.Bold, letterSpacing = 1.sp, color = tint,
|
||||
maxLines = 1, modifier = Modifier.padding(horizontal = 14.dp))
|
||||
icon != null -> Icon(painterResource(icon), contentDescription = null, tint = tint, modifier = Modifier.size(20.dp))
|
||||
vector != null -> Icon(vector, contentDescription = null, tint = tint, modifier = Modifier.size(20.dp))
|
||||
}
|
||||
if (shortcut != null) Text(
|
||||
shortcut, fontSize = 8.sp, lineHeight = 9.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.align(Alignment.BottomEnd).padding(end = 8.dp, bottom = 6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal val BAR_HEIGHT = 64.dp
|
||||
private val BAR_PAD = 12.dp
|
||||
private val BAR_GAP = 8.dp
|
||||
private val BUTTON = 44.dp
|
||||
private val STEAM_WIDTH = 80.dp
|
||||
private val MIN_TITLE = 72.dp
|
||||
|
||||
internal fun sessionBarModel(
|
||||
title: String?,
|
||||
onClose: (() -> Unit)?,
|
||||
onMenu: (() -> Unit)?,
|
||||
onSteam: () -> Unit,
|
||||
onQam: () -> Unit,
|
||||
extras: List<BarExtra> = emptyList(),
|
||||
): BottomBarModel {
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM
|
||||
return BottomBarModel(title, onClose, onMenu, onSteam.takeIf { steam }, onQam.takeIf { steam }, extras)
|
||||
}
|
||||
|
||||
internal fun bottomScreenBarView(context: Context, model: () -> BottomBarModel): ComposeView = ComposeView(context).apply {
|
||||
setContent { DroidDeckTheme { BottomScreenBar(model()) } }
|
||||
}
|
||||
@@ -39,18 +39,23 @@ class DeckControlsPanel(
|
||||
private val pad: PadBridge? = null,
|
||||
private val portraitDock: Boolean = false,
|
||||
private val onMenu: (() -> Unit)? = null,
|
||||
private val onSwap: (() -> 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) }
|
||||
|
||||
private val content = FrameLayout(context)
|
||||
val deckControls = pad == null || SessionState.deckPad
|
||||
private val tabViews = HashMap<Tab, TextView>()
|
||||
private val topBar: View by lazy { topBar() }
|
||||
private val topBar: View by lazy { tabsRow() }
|
||||
|
||||
init {
|
||||
orientation = VERTICAL
|
||||
setBackgroundColor(Color.BLACK)
|
||||
addView(topBar, LayoutParams(LayoutParams.MATCH_PARENT, dp(64)))
|
||||
val title = context.getString(if (deckControls) R.string.second_mode_deck_controls else R.string.deck_tab_gamepad)
|
||||
val extras = listOfNotNull(onSwap?.let { BarExtra(context.getString(R.string.swap_screens), icon = R.drawable.ic_bottom_swap, onClick = it) })
|
||||
addView(bottomScreenBarView(context) { sessionBarModel(title, onClose, onMenu, onSteamMenu, onQam, extras) },
|
||||
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
|
||||
addView(topBar, LayoutParams(LayoutParams.MATCH_PARENT, dp(52)))
|
||||
addView(content, LayoutParams(LayoutParams.MATCH_PARENT, 0, 1f))
|
||||
select(if (pad != null && !deckControls) Tab.GAMEPAD else if (pad != null) selectedWithPad else selected)
|
||||
}
|
||||
@@ -60,11 +65,10 @@ class DeckControlsPanel(
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
|
||||
private fun topBar(): View = LinearLayout(context).apply {
|
||||
private fun tabsRow(): View = LinearLayout(context).apply {
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
setPadding(dp(12), dp(10), dp(12), dp(6))
|
||||
addView(roundButton("×", context.getString(R.string.deck_close), onClose))
|
||||
gravity = Gravity.CENTER
|
||||
setPadding(dp(12), 0, dp(12), dp(8))
|
||||
val tabs = LinearLayout(context).apply {
|
||||
orientation = HORIZONTAL
|
||||
background = outline(CORNER_PILL, SURFACE)
|
||||
@@ -90,16 +94,7 @@ class DeckControlsPanel(
|
||||
overScrollMode = View.OVER_SCROLL_NEVER
|
||||
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)))
|
||||
addView(roundButton("•••", context.getString(R.string.drawer_open_qam), onQam, wide = true))
|
||||
}
|
||||
addView(centre, LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT))
|
||||
}
|
||||
|
||||
private fun select(tab: Tab) {
|
||||
@@ -122,7 +117,7 @@ class DeckControlsPanel(
|
||||
}
|
||||
}
|
||||
content.removeAllViews()
|
||||
topBar.visibility = if (tab == Tab.GAMEPAD) View.GONE else View.VISIBLE
|
||||
topBar.visibility = if (tab == Tab.GAMEPAD || tabViews.size < 2) View.GONE else View.VISIBLE
|
||||
content.addView(
|
||||
when (tab) {
|
||||
Tab.GRIPS -> gripsGrid()
|
||||
@@ -189,10 +184,6 @@ class DeckControlsPanel(
|
||||
place(pill("RB") { st, d -> st.press(PadState.RB, d) }, GamepadGeometry.Slot.RIGHT_INNER_SHOULDER)
|
||||
place(pill("RT") { st, d -> st.rightTrigger = if (d) 1f else 0f }, GamepadGeometry.Slot.RIGHT_OUTER_SHOULDER)
|
||||
place(pill("VIEW") { st, d -> st.press(PadState.SELECT, d) }, GamepadGeometry.Slot.VIEW)
|
||||
if (SessionState.mode == SessionService.MODE_STEAM) {
|
||||
place(centreTap("STEAM", context.getString(R.string.deck_open_steam_menu), onSteamMenu), GamepadGeometry.Slot.STEAM)
|
||||
place(centreTap("\u2022\u2022\u2022", context.getString(R.string.drawer_open_qam), onQam), GamepadGeometry.Slot.QAM)
|
||||
}
|
||||
place(pill("MENU") { st, d -> st.press(PadState.START, d) }, GamepadGeometry.Slot.MENU)
|
||||
if (deckControls) place(centreTap("\u25a6 " + context.getString(R.string.deck_panels), context.getString(R.string.deck_more_controls)) { select(Tab.BOTH) },
|
||||
GamepadGeometry.Slot.PANELS)
|
||||
@@ -258,7 +249,8 @@ class DeckControlsPanel(
|
||||
|
||||
private fun controlUnder(view: View, x: Float, y: Float): Boolean {
|
||||
if (view.visibility != VISIBLE || x < 0f || y < 0f || x >= view.width || y >= view.height) return false
|
||||
if (view.isClickable || view is HorizontalScrollView || view is Surface || view is DirectionPad || view is FaceButtons) return true
|
||||
if (view.isClickable || view is HorizontalScrollView || view is Surface || view is DirectionPad || view is FaceButtons ||
|
||||
view is androidx.compose.ui.platform.ComposeView) return true
|
||||
val group = view as? ViewGroup ?: return false
|
||||
return (group.childCount - 1 downTo 0).any { i ->
|
||||
val child = group.getChildAt(i)
|
||||
@@ -266,11 +258,6 @@ class DeckControlsPanel(
|
||||
}
|
||||
}
|
||||
|
||||
private fun roundButton(label: String, description: String, onClick: () -> Unit, wide: Boolean = false) =
|
||||
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) = outline(context, radius, fill)
|
||||
|
||||
private fun filled(radius: Float, fill: Int) = GradientDrawable().apply {
|
||||
|
||||
@@ -18,13 +18,36 @@ import androidx.compose.ui.window.Popup
|
||||
import androidx.compose.ui.window.PopupPositionProvider
|
||||
import androidx.compose.ui.window.PopupProperties
|
||||
|
||||
internal object KeyWindows {
|
||||
private val views = java.util.concurrent.CopyOnWriteArrayList<android.view.View>()
|
||||
|
||||
fun add(view: android.view.View) {
|
||||
views.remove(view)
|
||||
views.add(view)
|
||||
}
|
||||
|
||||
fun remove(view: android.view.View) { views.remove(view) }
|
||||
|
||||
fun topOn(displayId: Int): android.view.View? =
|
||||
views.lastOrNull { it.isAttachedToWindow && it.display?.displayId == displayId }
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun TrackKeyWindow() {
|
||||
val view = androidx.compose.ui.platform.LocalView.current
|
||||
androidx.compose.runtime.DisposableEffect(view) {
|
||||
KeyWindows.add(view)
|
||||
onDispose { KeyWindows.remove(view) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun GlideDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
properties: DialogProperties = DialogProperties(),
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
Dialog(onDismissRequest, properties) { FocusGlideHost(content = content) }
|
||||
Dialog(onDismissRequest, properties) { TrackKeyWindow(); FocusGlideHost(content = content) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -34,7 +57,10 @@ internal fun GlidePopup(
|
||||
properties: PopupProperties = PopupProperties(),
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
Popup(popupPositionProvider, onDismissRequest, properties) { FocusGlideHost(content = content) }
|
||||
Popup(popupPositionProvider, onDismissRequest, properties) {
|
||||
if (properties.focusable) TrackKeyWindow()
|
||||
FocusGlideHost(content = content)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -2,47 +2,29 @@ package com.droiddeck.launcher.ui
|
||||
|
||||
import com.droiddeck.launcher.R
|
||||
import android.app.Presentation
|
||||
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
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
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
|
||||
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
|
||||
import com.droiddeck.launcher.input.SecondScreenMode
|
||||
import com.droiddeck.launcher.input.TouchpadGestures
|
||||
import com.droiddeck.launcher.SessionActivity
|
||||
import com.droiddeck.launcher.session.BottomDesktop
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.session.SessionTerminal
|
||||
import com.termux.terminal.TerminalEmulator
|
||||
import com.termux.terminal.TerminalSession
|
||||
import com.termux.terminal.TerminalSessionClient
|
||||
import com.termux.view.TerminalView
|
||||
import com.termux.view.TerminalViewClient
|
||||
|
||||
class SecondScreenPresentation(
|
||||
private val sessionActivity: SessionActivity,
|
||||
@@ -59,6 +41,7 @@ class SecondScreenPresentation(
|
||||
private val menu: (@androidx.compose.runtime.Composable () -> Unit)? = null,
|
||||
private val dashboard: (@androidx.compose.runtime.Composable () -> Unit)? = null,
|
||||
private val onSwap: (() -> Unit)? = null,
|
||||
private val onMenuTouched: () -> Unit = {},
|
||||
) : Presentation(sessionActivity, display) {
|
||||
private val frame = FrameLayout(context)
|
||||
private var menuView: androidx.compose.ui.platform.ComposeView? = null
|
||||
@@ -67,20 +50,16 @@ class SecondScreenPresentation(
|
||||
private set
|
||||
private val root = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
setBackgroundColor(Color.rgb(15, 18, 22))
|
||||
setBackgroundColor(Color.BLACK)
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
private var currentMode = SecondScreenMode.NONE
|
||||
private var keyboardHost: KeyboardHost? = null
|
||||
private var keyboardButton: TextView? = null
|
||||
private val keyboardShown = androidx.compose.runtime.mutableStateOf(false)
|
||||
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
|
||||
private var ctrlActive = false
|
||||
private var altActive = false
|
||||
private var terminalPanel: SessionTerminalPanel? = null
|
||||
private var created = false
|
||||
|
||||
init {
|
||||
@@ -116,10 +95,10 @@ class SecondScreenPresentation(
|
||||
|
||||
private fun showPendingKeyboard() {
|
||||
keyboardPending = false
|
||||
keyboardButton?.text = context.getString(R.string.second_hide_keyboard)
|
||||
keyboardShown.value = true
|
||||
val host = keyboardHost ?: return
|
||||
for (delay in longArrayOf(150L, 450L)) root.postDelayed({
|
||||
val host = keyboardHost
|
||||
if (host != null && !imeSeen && showsKeyboard) host.show()
|
||||
if (keyboardHost === host && keyboardShown.value && !imeSeen && showsKeyboard) host.show()
|
||||
}, delay)
|
||||
}
|
||||
|
||||
@@ -135,7 +114,7 @@ class SecondScreenPresentation(
|
||||
fieldKeyboard = false
|
||||
imeSeen = false
|
||||
keyboardHost?.takeIf { it.shown }?.hide()
|
||||
keyboardButton?.text = context.getString(R.string.second_show_keyboard)
|
||||
keyboardShown.value = false
|
||||
onKeyboardClosed()
|
||||
}
|
||||
|
||||
@@ -146,7 +125,7 @@ class SecondScreenPresentation(
|
||||
}
|
||||
|
||||
fun retryTerminal() {
|
||||
if (created && isShowing && currentMode == SecondScreenMode.TERMINAL && terminalSession == null) renderMode()
|
||||
if (created && isShowing && currentMode == SecondScreenMode.TERMINAL && terminalPanel?.ready != true) renderMode()
|
||||
}
|
||||
|
||||
val showsKeyboard: Boolean get() = isShowing && !menuShown && currentMode == SecondScreenMode.KEYBOARD_TRACKPAD
|
||||
@@ -159,6 +138,7 @@ class SecondScreenPresentation(
|
||||
menuShown = on
|
||||
if (on) {
|
||||
keyboardHost?.takeIf { it.shown }?.hide()
|
||||
keyboardShown.value = false
|
||||
ownComposeViews()
|
||||
val view = menuView ?: androidx.compose.ui.platform.ComposeView(context).apply {
|
||||
isFocusable = true
|
||||
@@ -189,7 +169,10 @@ class SecondScreenPresentation(
|
||||
|
||||
fun focusMenu(): Boolean = menuView?.requestFocus() == true
|
||||
|
||||
fun dispatchMenuKey(event: KeyEvent): Boolean = menuView?.dispatchKeyEvent(event) == true
|
||||
fun dispatchMenuKey(event: KeyEvent): Boolean {
|
||||
KeyWindows.topOn(display.displayId)?.let { return it.rootView.dispatchKeyEvent(event) }
|
||||
return menuView?.dispatchKeyEvent(event) == true
|
||||
}
|
||||
|
||||
fun closeControls() {
|
||||
showMenu(false)
|
||||
@@ -203,11 +186,17 @@ class SecondScreenPresentation(
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
val ownKeys = currentMode == SecondScreenMode.TERMINAL || currentMode == SecondScreenMode.DASHBOARD ||
|
||||
currentMode == SecondScreenMode.DESKTOP
|
||||
val forward = menuShown || !ownKeys || PadBridge.isControllerKeyEvent(event)
|
||||
val back = event.keyCode == KeyEvent.KEYCODE_BACK && currentMode == SecondScreenMode.DASHBOARD
|
||||
val forward = menuShown || !ownKeys || back || PadBridge.isControllerKeyEvent(event)
|
||||
if (forward && sessionActivity.dispatchKeyEvent(event)) return true
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
if (menuShown && event.actionMasked == MotionEvent.ACTION_DOWN) onMenuTouched()
|
||||
return super.dispatchTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
|
||||
if (PadBridge.isControllerMotionEvent(event) && sessionActivity.dispatchGenericMotionEvent(event)) return true
|
||||
return super.dispatchGenericMotionEvent(event)
|
||||
@@ -226,11 +215,13 @@ class SecondScreenPresentation(
|
||||
fieldKeyboard = false
|
||||
keyboardHost?.hide()
|
||||
keyboardHost = null
|
||||
keyboardButton = null
|
||||
keyboardShown.value = false
|
||||
keyboardPending = false
|
||||
imeSeen = false
|
||||
closeTerminal()
|
||||
closeDashboard()
|
||||
root.removeAllViews()
|
||||
ownComposeViews()
|
||||
val mode = when {
|
||||
currentMode == SecondScreenMode.DECK_CONTROLS && !SessionState.deckPad -> SecondScreenMode.NONE
|
||||
currentMode == SecondScreenMode.DASHBOARD && dashboard == null -> SecondScreenMode.NONE
|
||||
@@ -242,10 +233,9 @@ class SecondScreenPresentation(
|
||||
when (mode) {
|
||||
SecondScreenMode.KEYBOARD_TRACKPAD -> renderKeyboardAndTrackpad()
|
||||
SecondScreenMode.TERMINAL -> renderTerminal()
|
||||
SecondScreenMode.DECK_CONTROLS -> root.addView(DeckControlsPanel(context, onClose, onSteamMenu, onQam, pad, onMenu = onMenu), weightParams())
|
||||
SecondScreenMode.DECK_CONTROLS -> root.addView(DeckControlsPanel(context, onClose, onSteamMenu, onQam, pad, onMenu = onMenu, onSwap = onSwap), weightParams())
|
||||
SecondScreenMode.DASHBOARD -> renderDashboard()
|
||||
SecondScreenMode.DESKTOP -> {
|
||||
ownComposeViews()
|
||||
root.addView(BottomDesktopPanel(context, onClose, onMenu,
|
||||
(onSteamMenu to onQam).takeIf { SessionState.mode == SessionService.MODE_STEAM }, onSwap), weightParams())
|
||||
}
|
||||
@@ -253,9 +243,17 @@ class SecondScreenPresentation(
|
||||
}
|
||||
}
|
||||
|
||||
private fun bar(mode: SecondScreenMode, extras: () -> List<BarExtra> = { emptyList() }) {
|
||||
root.addView(bottomScreenBarView(context) {
|
||||
sessionBarModel(context.getString(mode.label), onClose, onMenu, onSteamMenu, onQam, extras())
|
||||
}, LinearLayout.LayoutParams(-1, -2))
|
||||
}
|
||||
|
||||
private fun renderDashboard() {
|
||||
val content = dashboard ?: return
|
||||
ownComposeViews()
|
||||
bar(SecondScreenMode.DASHBOARD) {
|
||||
listOfNotNull(onSwap?.let { BarExtra(context.getString(R.string.swap_screens), icon = R.drawable.ic_bottom_swap, tag = "bottom-swap", onClick = it) })
|
||||
}
|
||||
val view = androidx.compose.ui.platform.ComposeView(context).apply { setContent { content() } }
|
||||
dashboardView = view
|
||||
root.addView(view, weightParams())
|
||||
@@ -267,170 +265,43 @@ class SecondScreenPresentation(
|
||||
}
|
||||
|
||||
private fun renderKeyboardAndTrackpad() {
|
||||
val panel = FrameLayout(context)
|
||||
panel.addView(trackpadView(), FrameLayout.LayoutParams(-1, -1))
|
||||
val controls = LinearLayout(context).apply {
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
setPadding(dp(12), dp(10), dp(12), dp(6))
|
||||
setBackgroundColor(Color.BLACK)
|
||||
}
|
||||
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
|
||||
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))
|
||||
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) {
|
||||
bar(SecondScreenMode.KEYBOARD_TRACKPAD) {
|
||||
listOf(BarExtra(context.getString(if (keyboardShown.value) R.string.second_hide_keyboard else R.string.second_show_keyboard),
|
||||
icon = R.drawable.ic_bottom_keyboard, active = keyboardShown.value, tag = "bottom-keyboard") {
|
||||
keyboardHost?.let { host ->
|
||||
host.toggle()
|
||||
keyboardButton.text = context.getString(if (host.shown) R.string.second_hide_keyboard else R.string.second_show_keyboard)
|
||||
keyboardShown.value = host.shown
|
||||
}
|
||||
}, 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(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())
|
||||
root.addView(trackpadView(), weightParams())
|
||||
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
|
||||
}
|
||||
host.onImeChanged = { visible -> if (!visible && keyboardShown.value) keyboardClosed() }
|
||||
keyboardHost = host
|
||||
root.addView(host, ViewGroup.LayoutParams(1, 1))
|
||||
}
|
||||
|
||||
private fun trackpadView(): View = TrackpadView(context)
|
||||
private fun trackpadView(): View = SessionTrackpadView(context, sendPointer, sendButton, sendWheel)
|
||||
|
||||
private fun renderTerminal() {
|
||||
val bar = LinearLayout(context).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
setPadding(dp(8), dp(4), dp(8), dp(4))
|
||||
setBackgroundColor(Color.rgb(27, 32, 38))
|
||||
}
|
||||
bar.addView(Button(context).apply {
|
||||
text = "×"
|
||||
contentDescription = context.getString(R.string.deck_close)
|
||||
minWidth = dp(48)
|
||||
setOnClickListener { onClose() }
|
||||
})
|
||||
bar.addView(TextView(context).apply {
|
||||
text = context.getString(R.string.second_terminal)
|
||||
textSize = 14f
|
||||
setTextColor(Color.WHITE)
|
||||
}, LinearLayout.LayoutParams(0, -2, 1f))
|
||||
bar.addView(Button(context).apply {
|
||||
text = context.getString(R.string.drawer_keyboard)
|
||||
setOnClickListener { showTerminalKeyboard() }
|
||||
})
|
||||
root.addView(bar, LinearLayout.LayoutParams(-1, -2))
|
||||
|
||||
val terminalClient = TerminalClient()
|
||||
val view = TerminalView(context, null).apply {
|
||||
setTerminalViewClient(terminalClient)
|
||||
setTextSize(dp(14))
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
terminalView = view
|
||||
val session = SessionTerminal.create(terminalClient)
|
||||
if (session == null) {
|
||||
root.addView(TextView(context).apply {
|
||||
text = context.getString(R.string.second_terminal_not_ready)
|
||||
setTextColor(Color.WHITE)
|
||||
gravity = Gravity.CENTER
|
||||
}, LinearLayout.LayoutParams(-1, 0, 1f))
|
||||
return
|
||||
}
|
||||
terminalSession = session
|
||||
|
||||
val keyStrip = HorizontalScrollView(context).apply { isHorizontalScrollBarEnabled = false }
|
||||
val keys = LinearLayout(context).apply { orientation = LinearLayout.HORIZONTAL; setPadding(dp(4), dp(2), dp(4), dp(2)) }
|
||||
fun key(label: String, input: String, onClick: ((Button) -> Unit)? = null) {
|
||||
val button = Button(context).apply {
|
||||
text = label
|
||||
setOnClickListener { if (onClick != null) onClick(this) else session.write(input) }
|
||||
}
|
||||
keys.addView(button)
|
||||
}
|
||||
val ctrl = context.getString(R.string.pckb_key_ctrl)
|
||||
val alt = context.getString(R.string.pckb_key_alt)
|
||||
key(context.getString(R.string.pckb_key_esc), "\u001b")
|
||||
key(context.getString(R.string.second_key_tab), "\t")
|
||||
key(ctrl, "") { button ->
|
||||
ctrlActive = !ctrlActive
|
||||
button.text = if (ctrlActive) context.getString(R.string.second_key_on, ctrl) else ctrl
|
||||
}
|
||||
key(alt, "") { button ->
|
||||
altActive = !altActive
|
||||
button.text = if (altActive) context.getString(R.string.second_key_on, alt) else alt
|
||||
}
|
||||
key("↑", "\u001b[A")
|
||||
key("↓", "\u001b[B")
|
||||
key("←", "\u001b[D")
|
||||
key("→", "\u001b[C")
|
||||
key(context.getString(R.string.second_key_ctrl_c), "\u0003")
|
||||
key(context.getString(R.string.second_key_ctrl_d), "\u0004")
|
||||
keyStrip.addView(keys)
|
||||
root.addView(keyStrip, LinearLayout.LayoutParams(-1, -2))
|
||||
|
||||
root.addView(view, LinearLayout.LayoutParams(-1, 0, 1f))
|
||||
view.attachSession(session)
|
||||
|
||||
view.post {
|
||||
registerTerminalPid()
|
||||
view.requestFocus()
|
||||
showTerminalKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showTerminalKeyboard() {
|
||||
terminalView?.let { view ->
|
||||
view.requestFocus()
|
||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||
.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerTerminalPid() {
|
||||
val pid = terminalSession?.pid ?: -1
|
||||
if (pid > 1 && pid != terminalPid) {
|
||||
terminalPid = pid
|
||||
SessionService.registerTerminalProcess(context, pid)
|
||||
bar(SecondScreenMode.TERMINAL) {
|
||||
listOf(BarExtra(context.getString(R.string.drawer_keyboard), icon = R.drawable.ic_bottom_keyboard, tag = "bottom-keyboard") {
|
||||
terminalPanel?.showKeyboard()
|
||||
})
|
||||
}
|
||||
val panel = SessionTerminalPanel(context)
|
||||
terminalPanel = panel
|
||||
root.addView(panel, weightParams())
|
||||
}
|
||||
|
||||
private fun closeTerminal() {
|
||||
terminalView?.let { view ->
|
||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||
.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
val pid = terminalPid.takeIf { it > 1 } ?: (terminalSession?.pid ?: -1)
|
||||
if (pid > 1) SessionService.stopTerminalProcess(context, pid)
|
||||
terminalPid = -1
|
||||
terminalSession = null
|
||||
terminalView = null
|
||||
ctrlActive = false
|
||||
altActive = false
|
||||
terminalPanel?.close()
|
||||
terminalPanel = null
|
||||
}
|
||||
|
||||
private fun dp(value: Int): Int = (value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
@@ -446,107 +317,4 @@ class SecondScreenPresentation(
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
|
||||
}
|
||||
|
||||
private inner class TrackpadView(context: Context) : View(context) {
|
||||
private val gestures = TouchpadGestures(ViewConfiguration.get(context).scaledTouchSlop.toFloat(),
|
||||
object : PointerGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) {
|
||||
sendPointer(x, y, width.toFloat(), height.toFloat())
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
|
||||
sendPointer(x, y, width.toFloat(), height.toFloat())
|
||||
sendButton(button, pressed)
|
||||
}
|
||||
|
||||
override fun onWheel(steps: Int) = sendWheel(steps)
|
||||
override fun onLongPress() { performHapticFeedback(android.view.HapticFeedbackConstants.LONG_PRESS) }
|
||||
})
|
||||
|
||||
init { isFocusable = true }
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
gestures.bounds = android.graphics.RectF(0f, 0f, w.toFloat(), h.toFloat())
|
||||
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)
|
||||
}
|
||||
|
||||
private inner class TerminalClient : TerminalSessionClient, TerminalViewClient {
|
||||
override fun onTextChanged(changedSession: TerminalSession) {
|
||||
terminalView?.onScreenUpdated()
|
||||
}
|
||||
override fun onTitleChanged(changedSession: TerminalSession) = Unit
|
||||
override fun onSessionFinished(finishedSession: TerminalSession) {
|
||||
val pid = terminalPid.takeIf { it > 1 } ?: finishedSession.pid
|
||||
if (pid > 1) SessionService.terminalProcessExited(context, pid)
|
||||
terminalPid = -1
|
||||
terminalView?.onScreenUpdated()
|
||||
}
|
||||
override fun onCopyTextToClipboard(session: TerminalSession, text: String) {
|
||||
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||
.setPrimaryClip(android.content.ClipData.newPlainText("Terminal", text))
|
||||
}
|
||||
override fun onPasteTextFromClipboard(session: TerminalSession) {
|
||||
val clip = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip
|
||||
if (clip != null && clip.itemCount > 0) session.write(clip.getItemAt(0).coerceToText(context).toString())
|
||||
}
|
||||
override fun onBell(session: TerminalSession) {
|
||||
terminalView?.performHapticFeedback(android.view.HapticFeedbackConstants.KEYBOARD_TAP)
|
||||
}
|
||||
override fun onColorsChanged(changedSession: TerminalSession) {
|
||||
terminalView?.invalidate()
|
||||
}
|
||||
override fun onTerminalCursorStateChange(state: Boolean) {
|
||||
terminalView?.setTerminalCursorBlinkerRate(if (state) 600 else 0)
|
||||
}
|
||||
override fun getTerminalCursorStyle(): Int = TerminalEmulator.TERMINAL_CURSOR_STYLE_BLOCK
|
||||
override fun logError(tag: String, message: String) { Log.e(tag, message) }
|
||||
override fun logWarn(tag: String, message: String) { Log.w(tag, message) }
|
||||
override fun logInfo(tag: String, message: String) { Log.i(tag, message) }
|
||||
override fun logDebug(tag: String, message: String) { Log.d(tag, message) }
|
||||
override fun logVerbose(tag: String, message: String) { Log.v(tag, message) }
|
||||
override fun logStackTraceWithMessage(tag: String, message: String, e: Exception) { Log.e(tag, message, e) }
|
||||
override fun logStackTrace(tag: String, e: Exception) { Log.e(tag, e.message, e) }
|
||||
|
||||
override fun onScale(scale: Float): Float = 1f
|
||||
override fun onSingleTapUp(e: MotionEvent) = showTerminalKeyboard()
|
||||
override fun shouldBackButtonBeMappedToEscape(): Boolean = true
|
||||
override fun shouldEnforceCharBasedInput(): Boolean = false
|
||||
override fun shouldUseCtrlSpaceWorkaround(): Boolean = false
|
||||
override fun isTerminalViewSelected(): Boolean = true
|
||||
override fun copyModeChanged(copyMode: Boolean) = Unit
|
||||
override fun onKeyDown(keyCode: Int, e: KeyEvent, session: TerminalSession): Boolean = false
|
||||
override fun onKeyUp(keyCode: Int, e: KeyEvent): Boolean = false
|
||||
override fun onLongPress(event: MotionEvent): Boolean = false
|
||||
override fun readControlKey(): Boolean = ctrlActive
|
||||
override fun readAltKey(): Boolean = altActive
|
||||
override fun readShiftKey(): Boolean = false
|
||||
override fun readFnKey(): Boolean = false
|
||||
override fun onCodePoint(codePoint: Int, ctrlDown: Boolean, session: TerminalSession): Boolean = false
|
||||
override fun onEmulatorSet() {
|
||||
terminalView?.onScreenUpdated()
|
||||
registerTerminalPid()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.droiddeck.launcher.ui
|
||||
internal enum class SessionDrawerPage(val firstControl: String) {
|
||||
CONTROLLER("touch"),
|
||||
GLASSES("glasses-game"),
|
||||
SECOND_SCREEN("second-screen:none"),
|
||||
SECOND_SCREEN("second-screen:keyboard-trackpad"),
|
||||
DISPLAY("fg"),
|
||||
HUD("hud"),
|
||||
EFFECTS("look"),
|
||||
|
||||
@@ -246,6 +246,7 @@ class DrawerActions(
|
||||
val textureAnisotropy: Int? = 0,
|
||||
val textureLodBias: String? = TextureFiltering.LOD_BIAS_OFF,
|
||||
val secondScreenMode: SecondScreenMode,
|
||||
val secondScreenNone: Boolean = true,
|
||||
val gameOnBottom: Boolean = false,
|
||||
val gameSwapAvailable: Boolean = false,
|
||||
val onGameOnBottom: (Boolean) -> Unit = {},
|
||||
@@ -319,6 +320,7 @@ class DrawerActions(
|
||||
val onStop: () -> Unit,
|
||||
val onStopFrom: ((androidx.compose.ui.geometry.Rect?) -> Unit)? = null,
|
||||
val onClose: () -> Unit,
|
||||
val onDismissScreen: (() -> Unit)? = null,
|
||||
val components: ComponentsManager.Snapshot? = null,
|
||||
val onComponentsRefresh: () -> Unit = {},
|
||||
val componentCatalog: List<ComponentsManager.CatalogItem> = emptyList(),
|
||||
@@ -422,7 +424,8 @@ 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}"
|
||||
page == SessionDrawerPage.SECOND_SCREEN -> "second-screen:" +
|
||||
(if (a.secondScreenMode == SecondScreenMode.NONE && !a.secondScreenNone) SecondScreenMode.KEYBOARD_TRACKPAD else a.secondScreenMode).id
|
||||
else -> page.firstControl
|
||||
}
|
||||
if (turned) focus.forget(page)
|
||||
@@ -452,7 +455,7 @@ 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 = if (docked) maxWidth else minOf(360.dp, maxWidth * 0.92f)
|
||||
val sheetWidth = if (docked) maxWidth else minOf(420.dp, maxWidth * 0.92f)
|
||||
val narrow = sheetWidth < 320.dp
|
||||
AnimatedVisibility(
|
||||
open,
|
||||
@@ -471,50 +474,52 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
}
|
||||
.padding(12.dp),
|
||||
) {
|
||||
val roomyHeader = sheetWidth >= 408.dp
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 44.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 44.dp)
|
||||
.then(if (roomyHeader) Modifier else Modifier.horizontalScroll(rememberScrollState())),
|
||||
) {
|
||||
if (docked) {
|
||||
SteamActionPill(
|
||||
stringResource(R.string.common_close), Icons.Outlined.Close, focus.track(page, "close"),
|
||||
) { host.open = null; a.onClose() }
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
SteamActionPill(
|
||||
stringResource(R.string.common_close), Icons.Outlined.Close, focus.track(page, "close"),
|
||||
) { host.open = null; (a.onDismissScreen ?: a.onClose)() }
|
||||
if (roomyHeader) Spacer(Modifier.weight(1f))
|
||||
SteamActionPill(
|
||||
stringResource(R.string.stores_dl_pause), Icons.Outlined.Pause, focus.track(page, "pause"),
|
||||
) { host.open = null; a.onPause() }
|
||||
if (a.pipSupported) SteamActionPill(
|
||||
stringResource(R.string.pip_title), Icons.Outlined.PictureInPictureAlt, focus.track(page, "pip"),
|
||||
) { host.open = null; a.onPip() }
|
||||
if (a.steam && a.onSteamMenu != null && a.onQam != null) {
|
||||
val qamInteraction = remember { MutableInteractionSource() }
|
||||
var qamStartedOnPress by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(qamInteraction) {
|
||||
qamInteraction.interactions.collect { interaction ->
|
||||
if (interaction is PressInteraction.Press) {
|
||||
qamStartedOnPress = true
|
||||
host.open = null
|
||||
a.onQam.invoke()
|
||||
}
|
||||
StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true }
|
||||
val steamActions = a.steam && a.onSteamMenu != null && a.onQam != null
|
||||
val qamInteraction = remember { MutableInteractionSource() }
|
||||
var qamStartedOnPress by remember { mutableStateOf(false) }
|
||||
if (steamActions) LaunchedEffect(qamInteraction) {
|
||||
qamInteraction.interactions.collect { interaction ->
|
||||
if (interaction is PressInteraction.Press) {
|
||||
qamStartedOnPress = true
|
||||
host.open = null
|
||||
a.onQam?.invoke()
|
||||
} else if (interaction is PressInteraction.Cancel) {
|
||||
qamStartedOnPress = false
|
||||
}
|
||||
}
|
||||
SteamActionPill(stringResource(R.string.drawer_steam_menu), Icons.Outlined.Home, focus.track(page, "steam"), shortcut = "⧉") {
|
||||
host.open = null
|
||||
a.onSteamMenu.invoke()
|
||||
}
|
||||
SteamActionPill(
|
||||
stringResource(R.string.drawer_open_qam), Icons.Outlined.MoreHoriz, focus.track(page, "qam"),
|
||||
interactionSource = qamInteraction, shortcut = "☰",
|
||||
onConfirm = { host.open = null; a.onQam.invoke() },
|
||||
) {
|
||||
host.open = null
|
||||
if (!qamStartedOnPress) a.onQam.invoke()
|
||||
qamStartedOnPress = false
|
||||
}
|
||||
}
|
||||
StopSessionButton(modifier = focus.track(page, "stop").onGloballyPositioned { stopCoords = it }) { host.open = null; confirmStop = true }
|
||||
BarActions(
|
||||
onMenu = { host.open = null; a.onClose() }, menuActive = true,
|
||||
onSteam = if (steamActions) ({ host.open = null; a.onSteamMenu?.invoke() }) else null,
|
||||
onQam = if (steamActions) ({
|
||||
host.open = null
|
||||
if (!qamStartedOnPress) a.onQam?.invoke()
|
||||
qamStartedOnPress = false
|
||||
}) else null,
|
||||
menuModifier = focus.track(page, "menu"),
|
||||
steamModifier = focus.track(page, "steam"),
|
||||
qamModifier = focus.track(page, "qam"),
|
||||
qamInteraction = qamInteraction,
|
||||
onQamConfirm = { host.open = null; a.onQam?.invoke() },
|
||||
)
|
||||
}
|
||||
a.onAchievements?.let { show ->
|
||||
DrawerAchievementsRow(a.achievementsProgress, Modifier.padding(top = if (short) 6.dp else 10.dp).then(focus.track(page, "achievements"))) {
|
||||
@@ -920,27 +925,7 @@ private fun SteamActionPill(
|
||||
onConfirm: (() -> Unit)? = null,
|
||||
shortcut: String? = null,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val hot = interactionSource.collectIsFocusedAsState().value || interactionSource.collectIsHoveredAsState().value
|
||||
val shape = RoundedCornerShape(22.dp)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier.size(44.dp).semantics { contentDescription = description }
|
||||
.clip(shape).background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
|
||||
.glideBorder(hot, shape, pal.signal, pal.line)
|
||||
.hoverable(interactionSource)
|
||||
.clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = interactionSource, indication = LocalIndication.current, onClick = onClick)
|
||||
.controllerConfirm(onClick = onConfirm ?: onClick),
|
||||
) {
|
||||
Icon(icon, contentDescription = null, tint = if (hot) pal.signal else colors.onBackground, modifier = Modifier.size(20.dp))
|
||||
if (shortcut != null) Text(
|
||||
shortcut, fontSize = 8.sp, lineHeight = 9.sp, color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.align(Alignment.BottomEnd).padding(end = 8.dp, bottom = 6.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
) = BarButton(description, modifier, vector = icon, shortcut = shortcut, interactionSource = interactionSource, onConfirm = onConfirm, onClick = onClick)
|
||||
|
||||
@Composable
|
||||
private fun DrawerBumper(label: String, description: String, modifier: Modifier = Modifier, onClick: () -> Unit) {
|
||||
@@ -1167,14 +1152,17 @@ private fun SteamVrRow(a: DrawerActions) {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun secondScreenModes(none: Boolean, deckPad: Boolean, dashboard: Boolean, desktop: Boolean): List<SecondScreenMode> =
|
||||
(if (none) listOf(SecondScreenMode.NONE) else emptyList()) + listOf(SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.TERMINAL) +
|
||||
(if (deckPad) listOf(SecondScreenMode.DECK_CONTROLS) else emptyList()) +
|
||||
(if (dashboard) listOf(SecondScreenMode.DASHBOARD) else emptyList()) +
|
||||
(if (desktop) listOf(SecondScreenMode.DESKTOP) else emptyList())
|
||||
|
||||
@Composable
|
||||
private fun SecondScreenGroup(host: MenuHost, a: DrawerActions, track: (String) -> Modifier) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val modes = listOf(SecondScreenMode.NONE, SecondScreenMode.KEYBOARD_TRACKPAD, SecondScreenMode.TERMINAL) +
|
||||
(if (com.droiddeck.launcher.session.SessionState.deckPad) listOf(SecondScreenMode.DECK_CONTROLS) else emptyList()) +
|
||||
(if (a.dashboardAvailable) listOf(SecondScreenMode.DASHBOARD) else emptyList()) +
|
||||
(if (a.desktopAvailable) listOf(SecondScreenMode.DESKTOP) else emptyList())
|
||||
val modes = secondScreenModes(a.secondScreenNone, com.droiddeck.launcher.session.SessionState.deckPad, a.dashboardAvailable, a.desktopAvailable)
|
||||
SettingsGroup(stringResource(R.string.drawer_second_screen_mode)) {
|
||||
Column(Modifier.fillMaxWidth().selectableGroup()) {
|
||||
modes.forEach { mode ->
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.util.Log
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.HorizontalScrollView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.PointerGestures
|
||||
import com.droiddeck.launcher.input.TouchpadGestures
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionTerminal
|
||||
import com.termux.terminal.TerminalEmulator
|
||||
import com.termux.terminal.TerminalSession
|
||||
import com.termux.terminal.TerminalSessionClient
|
||||
import com.termux.view.TerminalView
|
||||
import com.termux.view.TerminalViewClient
|
||||
|
||||
class SessionTrackpadView(
|
||||
context: Context,
|
||||
private val sendPointer: (x: Float, y: Float, width: Float, height: Float) -> Unit,
|
||||
private val sendButton: (button: Int, pressed: Boolean) -> Unit,
|
||||
private val sendWheel: (steps: Int) -> Unit,
|
||||
) : View(context) {
|
||||
private fun dp(value: Int): Int = (value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
private val gestures = TouchpadGestures(ViewConfiguration.get(context).scaledTouchSlop.toFloat(),
|
||||
object : PointerGestures.Listener {
|
||||
override fun onMove(x: Float, y: Float) {
|
||||
sendPointer(x, y, width.toFloat(), height.toFloat())
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
|
||||
sendPointer(x, y, width.toFloat(), height.toFloat())
|
||||
sendButton(button, pressed)
|
||||
}
|
||||
|
||||
override fun onWheel(steps: Int) = sendWheel(steps)
|
||||
override fun onLongPress() { performHapticFeedback(android.view.HapticFeedbackConstants.LONG_PRESS) }
|
||||
})
|
||||
|
||||
init {
|
||||
isFocusable = true
|
||||
setBackgroundColor(Color.BLACK)
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
gestures.bounds = android.graphics.RectF(0f, 0f, w.toFloat(), h.toFloat())
|
||||
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) {
|
||||
val inset = dp(12).toFloat()
|
||||
surface.set(inset, 0f, 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)
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
gestures.cancel()
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
}
|
||||
|
||||
class SessionTerminalPanel(context: Context) : LinearLayout(context) {
|
||||
private var terminalSession: TerminalSession? = null
|
||||
private var terminalView: TerminalView? = null
|
||||
private var terminalPid = -1
|
||||
private var ctrlActive = false
|
||||
private var altActive = false
|
||||
|
||||
val ready: Boolean get() = terminalSession != null
|
||||
|
||||
init {
|
||||
orientation = VERTICAL
|
||||
setBackgroundColor(Color.BLACK)
|
||||
build()
|
||||
}
|
||||
|
||||
private fun build() {
|
||||
val terminalClient = TerminalClient()
|
||||
val view = TerminalView(context, null).apply {
|
||||
setTerminalViewClient(terminalClient)
|
||||
setTextSize(dp(14))
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
terminalView = view
|
||||
val session = SessionTerminal.create(terminalClient)
|
||||
if (session == null) {
|
||||
addView(TextView(context).apply {
|
||||
text = context.getString(R.string.second_terminal_not_ready)
|
||||
setTextColor(Color.WHITE)
|
||||
gravity = Gravity.CENTER
|
||||
}, LayoutParams(-1, 0, 1f))
|
||||
return
|
||||
}
|
||||
terminalSession = session
|
||||
|
||||
val keyStrip = HorizontalScrollView(context).apply { isHorizontalScrollBarEnabled = false }
|
||||
val keys = LinearLayout(context).apply { orientation = HORIZONTAL; setPadding(dp(12), 0, dp(12), dp(8)) }
|
||||
fun key(label: String, input: String, onClick: ((TextView) -> Unit)? = null) {
|
||||
lateinit var button: TextView
|
||||
button = DeckControlsPanel.roundButton(context, label, label, { if (onClick != null) onClick(button) else session.write(input) }, wide = true)
|
||||
if (keys.childCount > 0) keys.addView(View(context), LinearLayout.LayoutParams(dp(8), 1))
|
||||
keys.addView(button)
|
||||
}
|
||||
val ctrl = context.getString(R.string.pckb_key_ctrl)
|
||||
val alt = context.getString(R.string.pckb_key_alt)
|
||||
key(context.getString(R.string.pckb_key_esc), "\u001b")
|
||||
key(context.getString(R.string.second_key_tab), "\t")
|
||||
key(ctrl, "") { button ->
|
||||
ctrlActive = !ctrlActive
|
||||
button.text = if (ctrlActive) context.getString(R.string.second_key_on, ctrl) else ctrl
|
||||
}
|
||||
key(alt, "") { button ->
|
||||
altActive = !altActive
|
||||
button.text = if (altActive) context.getString(R.string.second_key_on, alt) else alt
|
||||
}
|
||||
key("↑", "\u001b[A")
|
||||
key("↓", "\u001b[B")
|
||||
key("←", "\u001b[D")
|
||||
key("→", "\u001b[C")
|
||||
key(context.getString(R.string.second_key_ctrl_c), "\u0003")
|
||||
key(context.getString(R.string.second_key_ctrl_d), "\u0004")
|
||||
keyStrip.addView(keys)
|
||||
addView(keyStrip, LayoutParams(-1, -2))
|
||||
|
||||
addView(view, LayoutParams(-1, 0, 1f))
|
||||
view.attachSession(session)
|
||||
|
||||
view.post {
|
||||
registerTerminalPid()
|
||||
view.requestFocus()
|
||||
showKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
close()
|
||||
super.onDetachedFromWindow()
|
||||
}
|
||||
|
||||
fun showKeyboard() {
|
||||
terminalView?.let { view ->
|
||||
view.requestFocus()
|
||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||
.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerTerminalPid() {
|
||||
val pid = terminalSession?.pid ?: -1
|
||||
if (pid > 1 && pid != terminalPid) {
|
||||
terminalPid = pid
|
||||
SessionService.registerTerminalProcess(context, pid)
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
terminalView?.let { view ->
|
||||
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
|
||||
.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
val pid = terminalPid.takeIf { it > 1 } ?: (terminalSession?.pid ?: -1)
|
||||
if (pid > 1) SessionService.stopTerminalProcess(context, pid)
|
||||
terminalPid = -1
|
||||
terminalSession = null
|
||||
terminalView = null
|
||||
ctrlActive = false
|
||||
altActive = false
|
||||
}
|
||||
|
||||
private fun dp(value: Int): Int = (value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
private inner class TerminalClient : TerminalSessionClient, TerminalViewClient {
|
||||
override fun onTextChanged(changedSession: TerminalSession) {
|
||||
terminalView?.onScreenUpdated()
|
||||
}
|
||||
override fun onTitleChanged(changedSession: TerminalSession) = Unit
|
||||
override fun onSessionFinished(finishedSession: TerminalSession) {
|
||||
val pid = terminalPid.takeIf { it > 1 } ?: finishedSession.pid
|
||||
if (pid > 1) SessionService.terminalProcessExited(context, pid)
|
||||
terminalPid = -1
|
||||
terminalView?.onScreenUpdated()
|
||||
}
|
||||
override fun onCopyTextToClipboard(session: TerminalSession, text: String) {
|
||||
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||
.setPrimaryClip(android.content.ClipData.newPlainText("Terminal", text))
|
||||
}
|
||||
override fun onPasteTextFromClipboard(session: TerminalSession) {
|
||||
val clip = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip
|
||||
if (clip != null && clip.itemCount > 0) session.write(clip.getItemAt(0).coerceToText(context).toString())
|
||||
}
|
||||
override fun onBell(session: TerminalSession) {
|
||||
terminalView?.performHapticFeedback(android.view.HapticFeedbackConstants.KEYBOARD_TAP)
|
||||
}
|
||||
override fun onColorsChanged(changedSession: TerminalSession) {
|
||||
terminalView?.invalidate()
|
||||
}
|
||||
override fun onTerminalCursorStateChange(state: Boolean) {
|
||||
terminalView?.setTerminalCursorBlinkerRate(if (state) 600 else 0)
|
||||
}
|
||||
override fun getTerminalCursorStyle(): Int = TerminalEmulator.TERMINAL_CURSOR_STYLE_BLOCK
|
||||
override fun logError(tag: String, message: String) { Log.e(tag, message) }
|
||||
override fun logWarn(tag: String, message: String) { Log.w(tag, message) }
|
||||
override fun logInfo(tag: String, message: String) { Log.i(tag, message) }
|
||||
override fun logDebug(tag: String, message: String) { Log.d(tag, message) }
|
||||
override fun logVerbose(tag: String, message: String) { Log.v(tag, message) }
|
||||
override fun logStackTraceWithMessage(tag: String, message: String, e: Exception) { Log.e(tag, message, e) }
|
||||
override fun logStackTrace(tag: String, e: Exception) { Log.e(tag, e.message, e) }
|
||||
|
||||
override fun onScale(scale: Float): Float = 1f
|
||||
override fun onSingleTapUp(e: MotionEvent) = showKeyboard()
|
||||
override fun shouldBackButtonBeMappedToEscape(): Boolean = true
|
||||
override fun shouldEnforceCharBasedInput(): Boolean = false
|
||||
override fun shouldUseCtrlSpaceWorkaround(): Boolean = false
|
||||
override fun isTerminalViewSelected(): Boolean = true
|
||||
override fun copyModeChanged(copyMode: Boolean) = Unit
|
||||
override fun onKeyDown(keyCode: Int, e: KeyEvent, session: TerminalSession): Boolean = false
|
||||
override fun onKeyUp(keyCode: Int, e: KeyEvent): Boolean = false
|
||||
override fun onLongPress(event: MotionEvent): Boolean = false
|
||||
override fun readControlKey(): Boolean = ctrlActive
|
||||
override fun readAltKey(): Boolean = altActive
|
||||
override fun readShiftKey(): Boolean = false
|
||||
override fun readFnKey(): Boolean = false
|
||||
override fun onCodePoint(codePoint: Int, ctrlDown: Boolean, session: TerminalSession): Boolean = false
|
||||
override fun onEmulatorSet() {
|
||||
terminalView?.onScreenUpdated()
|
||||
registerTerminalPid()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,6 +263,7 @@ private class BelowEndProvider(private val gap: Int) : PopupPositionProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun AnchoredMenu(
|
||||
open: Boolean, onDismiss: () -> Unit, title: String? = null, note: String? = null,
|
||||
@@ -288,6 +289,20 @@ fun AnchoredMenu(
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
Popup(popupPositionProvider = provider, onDismissRequest = onDismiss, properties = PopupProperties(focusable = true)) {
|
||||
TrackKeyWindow()
|
||||
val popupInput = LocalInputModeManager.current
|
||||
LaunchedEffect(open, inputMode) {
|
||||
if (!open || inputMode != InputMode.Keyboard) return@LaunchedEffect
|
||||
popupInput.requestInputMode(InputMode.Keyboard)
|
||||
repeat(8) {
|
||||
androidx.compose.runtime.withFrameNanos { }
|
||||
if (runCatching { firstItemFocus.captureFocus() }.getOrDefault(false)) {
|
||||
firstItemFocus.freeFocus()
|
||||
return@LaunchedEffect
|
||||
}
|
||||
runCatching { firstItemFocus.requestFocus() }
|
||||
}
|
||||
}
|
||||
CompositionLocalProvider(LocalDensity provides density, LocalConfiguration provides configuration) {
|
||||
AnimatedVisibility(
|
||||
visibleState = state,
|
||||
|
||||
Reference in new issue
Block a user