mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Add top, bottom, and centered picture positions for Steam sessions (#871)
This commit is contained in:
1 parent
9fd13cec4d
commit
d3b0b8e51c
16 files changed
+207
-4
No files matched your search
@@ -120,6 +120,19 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private var pipUi by mutableStateOf(false)
|
||||
private var pipAutoEnter by mutableStateOf(false)
|
||||
private var unfoldedControls by mutableStateOf(false)
|
||||
private var picturePosition by mutableStateOf("center")
|
||||
|
||||
private fun applyGameAlignment() {
|
||||
if (!CompositorHost.isStarted) return
|
||||
val active = SessionState.mode == SessionService.MODE_STEAM &&
|
||||
!pipUi && !isInPictureInPictureMode && !cardboard.enabled
|
||||
val alignment = if (!active) ALIGN_CENTER else when (picturePosition) {
|
||||
"top" -> ALIGN_PICTURE_TOP
|
||||
"bottom" -> ALIGN_PICTURE_BOTTOM
|
||||
else -> ALIGN_CENTER
|
||||
}
|
||||
WaylandCompositor.nativeSetScaleMode(SCALE_FIT, alignment)
|
||||
}
|
||||
private var unfoldedPanel: com.droiddeck.launcher.ui.DeckControlsPanel? = null
|
||||
private lateinit var sessionRoot: FrameLayout
|
||||
private val guestKeysDown = mutableSetOf<Int>()
|
||||
@@ -463,6 +476,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
defaultFocusHighlightEnabled = false
|
||||
setContent {
|
||||
androidx.compose.runtime.LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, pipUi) { updatePointerCapture() }
|
||||
androidx.compose.runtime.LaunchedEffect(picturePosition, SessionState.running, pipUi, cardboard.enabled) { applyGameAlignment() }
|
||||
DroidDeckTheme {
|
||||
if (pipUi) {
|
||||
if (SessionState.suspended) androidx.compose.foundation.layout.Box(
|
||||
@@ -1056,6 +1070,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private fun readPrefs() {
|
||||
pipAutoEnter = SessionPrefs.pipAutoEnter(this)
|
||||
unfoldedControls = SessionPrefs.unfoldedControls(this)
|
||||
picturePosition = SessionPrefs.picturePosition(this)
|
||||
hudOn = SessionPrefs.hudEnabled(this)
|
||||
upscaler = SessionPrefs.upscaler(this)
|
||||
upscaleSharpness = SessionPrefs.upscaleSharpness(this)
|
||||
@@ -1291,6 +1306,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
)
|
||||
}
|
||||
applyFrameGen()
|
||||
applyGameAlignment()
|
||||
}
|
||||
|
||||
private var surfaceW = 0
|
||||
@@ -1960,9 +1976,15 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
else -> SessionState.mode != SessionService.MODE_STEAM || SessionState.steamUi == "desktop"
|
||||
}
|
||||
|
||||
private val gamePictureBounds = FloatArray(4)
|
||||
private var topPictureMapped = false
|
||||
|
||||
private fun drawnRect(): android.graphics.RectF? {
|
||||
val width = surfaceView.width.takeIf { it > 0 } ?: return null
|
||||
val height = surfaceView.height.takeIf { it > 0 } ?: return null
|
||||
topPictureMapped = CompositorHost.isStarted && WaylandCompositor.nativeGamePictureRect(gamePictureBounds)
|
||||
if (topPictureMapped) return android.graphics.RectF(
|
||||
gamePictureBounds[0], gamePictureBounds[1], gamePictureBounds[2], gamePictureBounds[3])
|
||||
val out = SessionState.outputSize
|
||||
val scale = minOf(width / out.first.toFloat(), height / out.second.toFloat())
|
||||
val drawnW = out.first * scale
|
||||
@@ -1972,6 +1994,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
return android.graphics.RectF(left, top, left + drawnW, top + drawnH)
|
||||
}
|
||||
|
||||
private var ignoreGameTouch = false
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (event.isFromSource(android.view.InputDevice.SOURCE_MOUSE)) return onMouse(event)
|
||||
if (routedTouchMode == SessionPrefs.TOUCH_OFF) return true
|
||||
@@ -1985,6 +2009,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
return touchpad.onTouch(event)
|
||||
}
|
||||
val rect = drawnRect() ?: return false
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN)
|
||||
ignoreGameTouch = topPictureMapped && !rect.contains(event.x, event.y)
|
||||
if (ignoreGameTouch) {
|
||||
if (event.actionMasked == MotionEvent.ACTION_DOWN)
|
||||
WaylandCompositor.nativeSendTouch(3, -1, 0, 0)
|
||||
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) ignoreGameTouch = false
|
||||
return true
|
||||
}
|
||||
fun sendTouch(action: Int, index: Int) {
|
||||
val x = event.getX(index).coerceIn(rect.left, rect.right)
|
||||
val y = event.getY(index).coerceIn(rect.top, rect.bottom)
|
||||
@@ -2533,6 +2565,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
private const val DRAWER_REPEAT_ACCELERATION_MS = 1_400L
|
||||
private const val SCALE_FIT = 1
|
||||
private const val ALIGN_CENTER = 0
|
||||
private const val ALIGN_PICTURE_TOP = 3
|
||||
private const val ALIGN_PICTURE_BOTTOM = 4
|
||||
private val RUNTIME_LINES = PackageLines(
|
||||
R.string.session_runtime_downloading, R.string.session_runtime_downloading_mb,
|
||||
R.string.session_runtime_checking, R.string.session_runtime_unpacking,
|
||||
|
||||
Reference in new issue
Block a user