Merge current main into PR #587

This commit is contained in:
Kurt Himebauch committed 2026-10-22 12:13:46 -04:00
commit 0819aa725d
151 files changed
+6687 -344

No files matched your search

@@ -44,6 +44,19 @@ object SessionDisplay {
fun unfoldedGameHeight(width: Int, height: Int): Int =
minOf(width * 9 / 16, (height * UNFOLDED_MAX_GAME_SHARE).toInt()) and 1.inv()
fun unfoldedControlsWanted(
enabled: Boolean,
foldable: Boolean,
controllerConnected: Boolean,
keepWithController: Boolean,
steamDeckPad: Boolean,
pip: Boolean,
width: Int,
height: Int,
smallestWidthDp: Int,
): Boolean = enabled && foldable && (keepWithController || !controllerConnected) && steamDeckPad &&
!pip && width > 0 && height > 0 && smallestWidthDp >= UNFOLDED_MIN_DP
fun panelSize(context: Context): Pair<Int, Int> {
val manager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
@@ -213,6 +213,7 @@ object SessionFiles {
if (!FileUtils.writeString(File(etc, "steam-compatibility-label"), context.getString(R.string.steam_compat_label))) {
Log.e(TAG, "could not write steam-compatibility-label")
}
writeCjkFontConfig(root, etc)
val droiddeckEtc = File(etc, "droiddeck").apply { mkdirs() }
val stagedSocket = File(droiddeckEtc, "bwrap-socket.staged")
if (!FileUtils.writeString(stagedSocket, BwrapSpawner.socket(context) + "\n")
@@ -554,4 +555,96 @@ object SessionFiles {
).joinToString(newline)
fun logDirectory(context: Context): File = LinuxRuntime.logDir(context).apply { mkdirs() }
/**
* Registers the Android system fonts (which include CJK faces such as Noto Sans CJK /
* MiSans) with the container's fontconfig, so the Steam Deck UI (CEF/webkit renderer)
* resolves Chinese/Japanese glyphs instead of showing tofu / mojibake.
* The fonts themselves are bind-mounted by LinuxRuntime.bindSystemFonts() into
* /usr/local/share/fonts/android; here we only need to point fontconfig at them.
*/
private fun writeCjkFontConfig(root: File, etc: File) {
try {
val confDir = File(etc, "fonts/conf.d").apply { mkdirs() }
val conf = File(confDir, "99-droiddeck-cjk.conf")
val xml = """<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/usr/local/share/fonts/android</dir>
<dir>/system/fonts</dir>
<match target="pattern">
<test name="lang" compare="contains"><string>ja</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK JP</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="contains"><string>ja</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK JP</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK SC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK SC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-cn</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK SC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-cn</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK SC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-tw</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK TC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-tw</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK TC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-hk</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK TC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="eq"><string>zh-hk</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK TC</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="contains"><string>ko</string></test>
<test name="family" qual="any"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Sans CJK KR</string></edit>
</match>
<match target="pattern">
<test name="lang" compare="contains"><string>ko</string></test>
<test name="family" qual="any"><string>serif</string></test>
<edit name="family" mode="prepend" binding="strong"><string>Noto Serif CJK KR</string></edit>
</match>
</fontconfig>
"""
if (!conf.isFile || FileUtils.readString(conf) != xml) {
val staged = File(confDir, conf.name + ".staged")
if (FileUtils.writeString(staged, xml) && staged.renameTo(conf)) {
Log.i(TAG, "Wrote CJK fontconfig 99-droiddeck-cjk.conf")
} else {
staged.delete()
Log.e(TAG, "Could not write CJK fontconfig")
}
}
} catch (e: Exception) {
Log.w(TAG, "CJK fontconfig setup failed", e)
}
}
}
@@ -759,6 +759,16 @@ object SessionPrefs {
prefs(context).edit().putString("theme", id).apply()
}
/** The custom Gradient theme's primary and secondary colours (ARGB). */
fun gradientColors(context: Context): Pair<Int, Int> = prefs(context).let {
it.getInt("gradientPrimary", com.droiddeck.launcher.ui.Themes.DEFAULT_PRIMARY) to
it.getInt("gradientSecondary", com.droiddeck.launcher.ui.Themes.DEFAULT_SECONDARY)
}
fun setGradientColors(context: Context, primary: Int, secondary: Int) {
prefs(context).edit().putInt("gradientPrimary", primary).putInt("gradientSecondary", secondary).apply()
}
private fun customResolution(context: Context, mode: String): Pair<Int, Int>? =
parseResolution(prefs(context).getString("customRes.$mode", null))
@@ -979,6 +989,13 @@ object SessionPrefs {
prefs(context).edit().putBoolean("unfoldedControls", enabled).apply()
}
fun unfoldedControlsWithController(context: Context): Boolean =
prefs(context).getBoolean("unfoldedControlsWithController", false)
fun setUnfoldedControlsWithController(context: Context, enabled: Boolean) {
prefs(context).edit().putBoolean("unfoldedControlsWithController", enabled).apply()
}
const val SURFACE_STICK = "stick"
const val SURFACE_TRACKPAD = "trackpad"
@@ -82,9 +82,16 @@ class SessionService : Service() {
private var suspendPolicy = SessionPrefs.SUSPEND_MANUAL
private var steamDownloadsInBackground = false
private var activityVisible = true
private var activityDisplayId = Display.DEFAULT_DISPLAY
private var xrActivityVisible = false
private var signInHold = false
private val hasVisibleSurface get() = sessionHasVisibleSurface(activityVisible || signInHold, screenOn, xrActivityVisible)
private val hasVisibleSurface get() = !SessionVisibilityPolicy.isHidden(
activityStarted = activityVisible || signInHold,
defaultDisplayOn = (getSystemService(Context.POWER_SERVICE) as? PowerManager)?.isInteractive ?: screenOn,
activityOnDefaultDisplay = activityDisplayId == Display.DEFAULT_DISPLAY,
activityDisplayOn = activityDisplayOn(),
xrActivityVisible = xrActivityVisible,
)
private var screenOn = true
private var sessionDisplayId = Display.DEFAULT_DISPLAY
private var manualPauseRequested = false
@@ -121,12 +128,22 @@ class SessionService : Service() {
private val displayListener = object : DisplayManager.DisplayListener {
override fun onDisplayAdded(displayId: Int) {}
override fun onDisplayRemoved(displayId: Int) {
if (displayId != sessionDisplayId) return
sessionDisplayId = Display.DEFAULT_DISPLAY
refreshScreenOn()
if (displayId == sessionDisplayId) {
sessionDisplayId = Display.DEFAULT_DISPLAY
refreshScreenOn()
}
if (displayId == activityDisplayId) {
suspendAttemptFailed = false
updateSuspendPolicy()
}
}
override fun onDisplayChanged(displayId: Int) {
if (displayId == sessionDisplayId && displayId != Display.DEFAULT_DISPLAY) refreshScreenOn()
if (displayId == activityDisplayId) {
resumeSteamSleepOnReturn()
suspendAttemptFailed = false
updateSuspendPolicy()
}
}
}
@@ -138,6 +155,14 @@ class SessionService : Service() {
interactive ?: (getSystemService(Context.POWER_SERVICE) as? PowerManager)?.isInteractive ?: true, state)
}
private fun activityDisplayOn(): Boolean {
if (activityDisplayId == Display.DEFAULT_DISPLAY) {
return (getSystemService(Context.POWER_SERVICE) as? PowerManager)?.isInteractive ?: screenOn
}
val displays = getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager ?: return false
return displays.getDisplay(activityDisplayId)?.state == Display.STATE_ON
}
private fun refreshScreenOn() {
val on = readScreenOn()
if (on == screenOn) return
@@ -208,6 +233,7 @@ class SessionService : Service() {
ACTION_ACTIVITY_VISIBLE -> {
if (!SessionState.pipActive) pipTask = false
activityVisible = true
activityDisplayId = intent.getIntExtra(EXTRA_ACTIVITY_DISPLAY_ID, activityDisplayId)
sessionDisplayId = intent.getIntExtra(EXTRA_DISPLAY_ID, sessionDisplayId)
screenOn = readScreenOn()
suspendDownloadNow = false
@@ -221,8 +247,16 @@ class SessionService : Service() {
refreshScreenOn()
return START_NOT_STICKY
}
ACTION_ACTIVITY_DISPLAY_CHANGED -> {
activityDisplayId = intent.getIntExtra(EXTRA_ACTIVITY_DISPLAY_ID, activityDisplayId)
resumeSteamSleepOnReturn()
suspendAttemptFailed = false
updateSuspendPolicy()
return START_NOT_STICKY
}
ACTION_ACTIVITY_HIDDEN -> {
activityVisible = false
activityDisplayId = intent.getIntExtra(EXTRA_ACTIVITY_DISPLAY_ID, activityDisplayId)
suspendAttemptFailed = false
updateSuspendPolicy()
return START_NOT_STICKY
@@ -285,6 +319,7 @@ class SessionService : Service() {
xrActivityVisible = false
signInHold = false
sessionDisplayId = intent?.getIntExtra(EXTRA_DISPLAY_ID, Display.DEFAULT_DISPLAY) ?: Display.DEFAULT_DISPLAY
activityDisplayId = intent?.getIntExtra(EXTRA_ACTIVITY_DISPLAY_ID, sessionDisplayId) ?: sessionDisplayId
screenOn = readScreenOn()
manualPauseRequested = false
suspendDownloadNow = false
@@ -1867,7 +1902,9 @@ class SessionService : Service() {
private const val ACTION_ACTIVITY_VISIBLE = "com.droiddeck.launcher.ACTIVITY_VISIBLE"
private const val ACTION_ACTIVITY_HIDDEN = "com.droiddeck.launcher.ACTIVITY_HIDDEN"
private const val ACTION_ACTIVITY_DISPLAY = "com.droiddeck.launcher.ACTIVITY_DISPLAY"
private const val ACTION_ACTIVITY_DISPLAY_CHANGED = "com.droiddeck.launcher.ACTIVITY_DISPLAY_CHANGED"
private const val EXTRA_DISPLAY_ID = "displayId"
private const val EXTRA_ACTIVITY_DISPLAY_ID = "activityDisplayId"
private const val ACTION_XR_ACTIVITY_VISIBLE = "com.droiddeck.launcher.XR_ACTIVITY_VISIBLE"
private const val ACTION_XR_ACTIVITY_HIDDEN = "com.droiddeck.launcher.XR_ACTIVITY_HIDDEN"
private const val ACTION_SIGN_IN_HOLD = "com.droiddeck.launcher.SIGN_IN_HOLD"
@@ -1912,8 +1949,10 @@ class SessionService : Service() {
steamUi: String? = null, steamUrl: String? = null, programArgs: Array<String>? = null,
displayId: Int = Display.DEFAULT_DISPLAY,
) {
SessionState.activityDisplayId = displayId
val intent = Intent(context, SessionService::class.java).putExtra(EXTRA_MODE, mode)
.putExtra(EXTRA_DISPLAY_ID, displayId)
.putExtra(EXTRA_ACTIVITY_DISPLAY_ID, displayId)
if (program != null) intent.putExtra(EXTRA_PROGRAM, program)
if (programArgs != null) intent.putExtra(EXTRA_PROGRAM_ARGS, programArgs)
if (steamUi != null) intent.putExtra(EXTRA_STEAM_UI, steamUi)
@@ -1934,15 +1973,29 @@ class SessionService : Service() {
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_PIP_BEGIN))
}
fun setActivityVisible(context: Context, visible: Boolean, displayId: Int = Display.DEFAULT_DISPLAY) {
fun setActivityVisible(context: Context, visible: Boolean, displayId: Int = contextDisplayId(context)) {
if (!SessionState.running) return
val action = if (visible) ACTION_ACTIVITY_VISIBLE else ACTION_ACTIVITY_HIDDEN
context.startService(Intent(context, SessionService::class.java).setAction(action).putExtra(EXTRA_DISPLAY_ID, displayId))
SessionState.activityDisplayId = displayId
context.startService(Intent(context, SessionService::class.java).setAction(action)
.putExtra(EXTRA_DISPLAY_ID, displayId)
.putExtra(EXTRA_ACTIVITY_DISPLAY_ID, displayId))
}
fun setActivityDisplay(context: Context, displayId: Int) {
if (!SessionState.running) return
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_ACTIVITY_DISPLAY).putExtra(EXTRA_DISPLAY_ID, displayId))
SessionState.activityDisplayId = displayId
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_ACTIVITY_DISPLAY)
.putExtra(EXTRA_DISPLAY_ID, displayId))
context.startService(Intent(context, SessionService::class.java).setAction(ACTION_ACTIVITY_DISPLAY_CHANGED)
.putExtra(EXTRA_ACTIVITY_DISPLAY_ID, displayId))
}
@Suppress("DEPRECATION")
private fun contextDisplayId(context: Context): Int {
val activity = context as? android.app.Activity ?: return Display.DEFAULT_DISPLAY
return if (Build.VERSION.SDK_INT >= 30) activity.display?.displayId ?: activity.windowManager.defaultDisplay.displayId
else activity.windowManager.defaultDisplay.displayId
}
fun setXrActivityVisible(context: Context, visible: Boolean) {
@@ -42,6 +42,8 @@ object SessionState {
@Volatile
var running = false
@Volatile
var activityDisplayId = 0
@Volatile
var runtimeDriver: String? = null
var suspended by mutableStateOf(false)
@Volatile var pipActive = false
@@ -0,0 +1,15 @@
package com.droiddeck.launcher.session
internal object SessionVisibilityPolicy {
fun isHidden(
activityStarted: Boolean,
defaultDisplayOn: Boolean,
activityOnDefaultDisplay: Boolean,
activityDisplayOn: Boolean,
xrActivityVisible: Boolean = false,
): Boolean = !sessionHasVisibleSurface(
panelVisible = activityStarted,
screenOn = if (activityOnDefaultDisplay) defaultDisplayOn else activityDisplayOn,
xrVisible = xrActivityVisible,
)
}
@@ -15,7 +15,8 @@ object SettingsReset {
"gameStoresEnabled", "gameStoresSpeedTier", "gameStoresParallel", "storesOpenTab", "storesShowMature",
"storesInstallLanguage",
"hud", "hudDeck", "hudFps", "hudBattery", "hudGraph", "hudColor", "hudOpacity", "backActionsInverted", "touch", "osc", "shape", "steamController",
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "stretch16x9", "picturePosition",
"gamepadLeft", "gamepadRight", "pipAutoEnter", "unfoldedControls", "unfoldedControlsWithController",
"stretch16x9", "picturePosition",
"gpuDriverMode", "androidDriver", "linuxDriver", "linuxDriver.steam", "linuxDriver.desktop",
"tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime",
"directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus",
@@ -369,7 +369,9 @@ object WinComponents {
val archiveName = archive.optString("name")
val url = c.snapshot.substringBeforeLast('/') + "/" + archiveName
val file = File(work, "${c.name}.files.tar.xz")
if (!Downloader.downloadFile(url, file, false) { f -> onProgress(Progress(c.name, archiveName, Phase.DOWNLOAD, if (f < 0) -1 else Math.round(f * 100f))) }) {
// The snapshot came straight from github.com, so its digest may vouch for a mirror's copy of the archive.
val sha = archive.optString("sha256").takeIf { it.matches(Regex("(?i)[0-9a-f]{64}")) }
if (!Downloader.downloadFile(url, file, false, sha) { f -> onProgress(Progress(c.name, archiveName, Phase.DOWNLOAD, if (f < 0) -1 else Math.round(f * 100f))) }) {
return null to "download failed: $archiveName"
}
archive.optString("sha256").takeIf { it.length == 64 }?.let { sha ->